Menu
  • HOME
  • TAGS

Reading wrong class type with NSKeyedUnarchiver

ios,objective-c,nsobject,nskeyedarchiver,nskeyedunarchiver

The initWithCoder: method is just like any other init method - it must call super and return an instance. Your method should be: - (instancetype) initWithCoder:(NSCoder *)coder { self = [super init]; if(self) self.geoLocation = [coder decodeObjectForKey:@"geoLocation"]; return self; } If your superclass implements initWithCoder: as well the super call...

Archiving Multiple Objects and Unarchiving them as array of objects in objective C

objective-c,nskeyedarchiver,nskeyedunarchiver

In order to save a custom class with NSKeyedArchiver, that class needs to implement the NSCoding protocol. Even if instances of your class are included as members of an NSArray or NSDictionary you need to have them conform. Using createFileAtPath:contents:attributes: will overwrite the contents of that file. Here are some...

Custom class archiving in Swift

ios,swift,nskeyedarchiver,nskeyedunarchiver

You can archive/unarchive a CGPoint using : encodeCGPoint:forKey: and decodeCGPointForKey: More information here : https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSCoder_Class/index.html#//apple_ref/occ/instm/NSCoder/encodeCGPoint:forKey:...

Core Data message Unable to find an instance of NSValueTransformer registered for the name: NSKeyedUnarchiveFromDataTransformerName

core-data,nskeyedunarchiver

It seems that the transformer class name has been set to NSKeyedUnarchiveFromDataTransformerName, and that a class with that name doesn't exist. You'll either need to remove that class name and a default serialiser will be used or you need to create that class and have it perform some custom archiving....

How to deal with unarchiver with this situation..?

ios,objective-c,nskeyedunarchiver

The easier way out is to use exception handling: @try { self.favouritesList = [[NSKeyedUnarchiver unarchiveObjectWithFile:self.fileName] mutableCopy]; } @catch ( NSException *e ) { self.favouritesList = [[NSMutableArray alloc]init]; // add more code as needed } Apple's documentation is here. https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Exceptions/Tasks/HandlingExceptions.html#//apple_ref/doc/uid/20000059-BBCHGJIJ...

NSKeyedUnarchiver unarchiveObjectWithData: in Parse block function never returns

ios,parse.com,nskeyedunarchiver

As it turned out the data was being stored as a plist and I needed to use plist serialization to extract it: if (data) { NSError *error; NSPropertyListFormat format; NSDictionary* plist = [NSPropertyListSerialization propertyListWithData:data options:NSPropertyListImmutable format:&format error:&error]; if(!plist){ NSLog(@"Error: %@",error); } ...

NSKeyedArchiver would not save or load objects

ios,objective-c,nskeyedarchiver,nscoding,nskeyedunarchiver

unarchiveObjectWithFile: returns the unarchived object for you to use. At the moment you just check if it is nil (with your if statement) and then it gets destroyed (deallocated because you don't use it, assuming you're using ARC). So, get the object returned by unarchiveObjectWithFile: and set it to your...

Swift - NSKeyedUnarchiver unarchiveObjectWithData in NSMutableArray

ios,swift,nsmutablearray,nskeyedunarchiver

Just downcast the result to NSMutableArray: if let objects = NSKeyedUnarchiver.unarchiveObjectWithData(data) as? NSMutableArray { // ... } else { // failed } If the archived object is an (immutable) NSArray then you have to create a mutable copy: if let array = NSKeyedUnarchiver.unarchiveObjectWithData(data) as? NSArray { let objects = NSMutableArray(array:...

NSInvalidUnarchiveOperationException when unarchieving custom class

objective-c,osx,runtime,nsdata,nskeyedunarchiver

The problem here is that the runtime didn't load all the class present in my static library. As I had no direct call to that class (only id), it was never loaded. I fixed it by adding -objC in "other linker flags" in the build settings. Some informations about why...