nskeyedunarchiver

NSKeyedUnarchiver.unarchiveTopLevelObjectWithData return nil

房东的猫 提交于 2021-02-11 15:14:16
问题 I want to save an array of objects into UserDefaults and load it back. When trying to unarchive the data it always returns nil.. any idea? This is my object: class DbInsideLevel: NSObject, NSSecureCoding { static var supportsSecureCoding: Bool { return true } let idNum: Int! var topicId: Int = 0 var tryCount: Int = 0 var score: Int = 0 var isOpen: Bool = false var lastPlayedDate: Date? init(idNum: Int, topicId: Int, tryCount: Int = 0, score: Int = 0, open: Bool, lastPlayedDate: Date?) { self

NSKeyedUnarchiver decodeObjectForKey: cannot decode object of class for key (NS.objects)

[亡魂溺海] 提交于 2021-02-10 07:06:57
问题 I looked through whole SO but still no answer. My app reports this problem: Fatal Exception: NSInvalidUnarchiveOperationException *** -[NSKeyedUnarchiver decodeObjectForKey:]: cannot decode object of class (App_Title.Products) for key (NS.objects); the class may be defined in source code or a library that is not linked I did already do NSKeyedUnarchiver.setClass just before #unarchiveObject: func loadProducts() -> [Products]? { NSKeyedUnarchiver.setClass(Products.self, forClassName: "Products

Store Custom Objects in NSUserDefaults

放肆的年华 提交于 2020-02-25 23:06:25
问题 I am trying to store a custom objects as follows, but I am getting an error. // store data NSMutableArray *archiveArray = [NSMutableArray arrayWithCapacity:pOrderElements.count]; for (id orderObject in pOrderElements) { NSData *personEncodedObject = [NSKeyedArchiver archivedDataWithRootObject:orderObject]; [archiveArray addObject:personEncodedObject]; } NSUserDefaults *userData = [NSUserDefaults standardUserDefaults]; [userData setObject:archiveArray forKey:@"personDataArray"]; // retrive

How to NSKeyedUnarchiver.unarchiveObject

陌路散爱 提交于 2020-01-24 09:20:11
问题 I have a working code that works but deprecated: This part is fine: let archived = try? NSKeyedArchiver.archivedData(withRootObject: [defaultRecord] as NSArray, requiringSecureCoding: false) This is Deprecated: let records = NSKeyedUnarchiver.unarchiveObject(with: unarchivedObject as Data) as? [Record] 'unarchiveObject(with:)' was deprecated in iOS 12.0: Use +unarchivedObjectOfClass:fromData:error: instead Sounds simple as it is, I couldn't find a way to use the suggested method without

Swift only way to prevent NSKeyedUnarchiver.decodeObject crash?

瘦欲@ 提交于 2020-01-09 13:09:02
问题 NSKeyedUnarchiver.decodeObject will cause a crash / SIGABRT if the original class is unknown. The only solution I have seen to catching this issue dates from Swift's early history and required using Objective C (also pre-dated Swift 2's implementation of guard , throws , try & catch ). I could figure out the Objective C route - but I would prefer to understand a Swift-only solution if possible. For example - the data has been encoded with NSPropertyListFormat.XMLFormat_v1_0 . The following

Swift only way to prevent NSKeyedUnarchiver.decodeObject crash?

ぃ、小莉子 提交于 2020-01-09 13:08:26
问题 NSKeyedUnarchiver.decodeObject will cause a crash / SIGABRT if the original class is unknown. The only solution I have seen to catching this issue dates from Swift's early history and required using Objective C (also pre-dated Swift 2's implementation of guard , throws , try & catch ). I could figure out the Objective C route - but I would prefer to understand a Swift-only solution if possible. For example - the data has been encoded with NSPropertyListFormat.XMLFormat_v1_0 . The following

app crashes at run before reaching my code xcode6.1 Universal App Objective-C NSKeyedUnarchiver iOS 7.0 iOS 8.1

懵懂的女人 提交于 2019-12-24 14:54:23
问题 App crashes at run under 7.1 simulator or device and runs fine on both with in 8.1 with StackTrace: appName[10676:607] *** -[NSKeyedUnarchiver initForReadingWithData:]: data is empty; did you forget to send -finishEncoding to the NSKeyedArchiver? appName[10676:607] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '(null)' *** First throw call stack: ( 0 CoreFoundation 0x007a91e4 __exceptionPreprocess + 180 1 libobjc.A.dylib 0x005258e5 objc_exception

Swift NSCoding - How to read an encoded array

百般思念 提交于 2019-12-24 08:00:03
问题 I'm using Swift playground to write a parent-child relationship using NSCoding. The relationship can be described as: One Author can write many Books However, it causes an error when I try to save the collection of books; Playground execution aborted: error: Execution was interrupted, reason: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0). The process has been left at the point where it was interrupted, use "thread return -x" to return to the state before expression evaluation. My

How to use the delegates with NSKeyedUnarchiver?

亡梦爱人 提交于 2019-12-23 07:28:13
问题 I am using NSKeyedUnarchiver to unarchive an object and would like to use the delegates (NSKeyedUnarchiverDelegate), but my delegates are not called. Archiving and Unarchiving is working fine, but the Delegates (unarchiver & unarchiverDidFinish) are not called. Can someone help? I have the following implementation: class BlobHandler: NSObject , NSKeyedUnarchiverDelegate{ func load() -> MYOBJECTCLASS{ let data:NSData? = getBlob(); var mykeyedunarchiver:NSKeyedUnarchiver=NSKeyedUnarchiver

Load SpriteKit levels from filename

半世苍凉 提交于 2019-12-21 20:44:28
问题 For a game I'm creating, I want to be able to create a lot of custom levels that can be loaded easily. Each level should have a .sks interface file and its own SKScene subclass .swift file. Right now, this is working: extension SKScene { class func unarchiveFromFile(file : NSString, theClass : AnyClass!) -> SKScene? { if let path = NSBundle.mainBundle().pathForResource(file, ofType: "sks") { var sceneData = NSData.dataWithContentsOfFile(path, options: .DataReadingMappedIfSafe, error: nil) var