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...
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...
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:...
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....
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...
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); } ...
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...
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:...
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...