FAQ Database Discussion Community


NSUserdefaults not working with NSKeyedArchiver

ios,objective-c,nsuserdefaults,nscoding,nskeyedarchiver
I have a NSMutableArray filled with objects of my Movie class wich i want to save but it doesn't work and i can not figure out why... Movie.h: @interface Movie : NSObject <NSCoding>{ NSString *name; int year; int length; NSString *file_size; int rating; NSArray *genre; NSString *plot; } @property (nonatomic,...

Cannot change the frame properties of a UIView

ios,swift,uiview,frame,nskeyedarchiver
I have a UIView @IBOutlet weak var myView: UIView! I copy it using NSArchiver var topview = NSKeyedUnarchiver.unarchiveObjectWithData(NSKeyedArchiver.archivedDataWithRootObject(self.myView)); I attempt to alter it using CGRectMake topview?.frame = CGRectMake(0, 0, self.view.frame.width, self.view.frame.height * 1.5) In response to the line above's '=' I receive the error Cannot assign to result of this...

NSMutable dictionary, do I initialise every time it is used or save and load it to file?

ios,objective-c,nsmutabledictionary,nskeyedarchiver
I have a class that uses a NSMutableDictionary. This dictionary contains between 40-60 objects of a custom class "appStrings". Right now every time I used the class I just init the dictionary calling my initDictionary method and this adds all the objects and keys. Is it better/faster to instead init...

Custom class archiving in Swift

ios,swift,nskeyedarchiver,nskeyedunarchiver
I would like to archive and unarchive a custom object in swift, something like this: class Line : NSObject, NSCoding { var start : CGPoint init(start _start: CGPoint) { start = _start } required init(coder aDecoder: NSCoder) { // 1 - compile time error self.start = aDecoder.decodeObjectForKey("start") as CGPoint }...

Save and retrieve value via KeyChain

ios,swift,keychain,nskeyedarchiver
I'm trying to store an Integer and retrieve it using KeyChain. This is how I save it: func SaveNumberOfImagesTaken() { let key = "IMAGE_TAKEN" var taken = 10 let data = NSKeyedArchiver.archivedDataWithRootObject(taken) let query : [String:AnyObject] = [ kSecClass as String : kSecClassGenericPassword, kSecAttrAccount as String : key, kSecValueData as...

How to save list of own classes in a plist in XML format using NSKeyedArchiver (or other mechanics)?

ios,xml,swift,plist,nskeyedarchiver
I manage to write a plist in binary format to disk. But I do not manage to write the data in XML format. I read this should be possible, but there is no sample code or documentation doing this. Code for storing which works: var listofbookmarks = [Bookmark]() // <-...

How to migrate an object which has been persisted with NSKeyedArchiver?

ios,migration,nscoding,nskeyedarchiver,object-persistence
I'm using a version of Archiver and have run into an issue. In a previous version of my project a class, Challenge was serialized to disk //v1.0 @interface Challenge : NSObject<NSCoding> { ... @property (nonatomic,strong) NSString *challengeId; @property (nonatomic,strong) NSString *title; @property (nonatomic) BOOL isCompleted; ... } Now, in version...

NSKeyedArchiver: key returning nil - Swift

ios,swift,null,nskeyedarchiver
I'm having some issues here. I'm trying to store some information with NSKeyedArchiver, but when I run the app, I get: fatal error: unexpectedly found nil while unwrapping an Optional value. Apple docs says: "If you invoke one of the decode... methods of this class using a key that does...

Swift structs to NSData and back

swift,serialization,struct,nsdata,nskeyedarchiver
I have a struct containing a struct and an NSObject that I want to serialize into an NSData object: struct Packet { var name: String var index: Int var numberOfPackets: Int var data: NSData } var thePacket = Packet(name: name, index: i, numberOfPackets: numberOfPackets, data: packetData) How do I best...

Watchkit sharing data with iPhone app, NSInvalidUnarchiveOperationException

nskeyedarchiver,watchkit
From my iPhone app I'm sending data to my Watch app through: func application(application: UIApplication!, handleWatchKitExtensionRequest userInfo: [NSObject : AnyObject]!, reply: (([NSObject : AnyObject]!) -> Void)!) { if let data = NSKeyedArchiver.archivedDataWithRootObject(Country()) { reply(["data": data]) } } In my Watch app I'm trying to read the data: WKInterfaceController.openParentApplication(input, reply: {...