nscoding

Saving an NSArray of custom objects

心不动则不痛 提交于 2019-12-01 11:08:29
I've created a subclass of UIImage (UIImageExtra) as I want to include extra properties and methods. I have an array that contains instances of this custom class.However when I save the array, it appears the extra data in the UIImageExtra class is not saved. UIImageExtra conforms to NSCoding, but neither initWithCoder or encodeWithCoder are called, as NSLog statements I've added aren't printed. My method to save the array looks like this: - (void)saveIllustrations { if (_illustrations == nil) { NSLog(@"Nil array"); return; } [self createDataPath]; //Serialize the data and write to disk

How to use persist & retrieve an NSCoding compliant object to app Document directory in Swift 3?

六眼飞鱼酱① 提交于 2019-12-01 10:42:00
问题 Here's a NSCoding compliant object. I would like to save and recover it from the app's documents directory in Swift 3. I imagine it's a save method and recover method. How is this done? import Foundation class Book: NSObject, NSCoding { var title: String var author: String var pageCount: Int var categories: [String] var available: Bool init(title:String, author: String, pageCount:Int, categories:[String],available:Bool) { self.title = title self.author = author self.pageCount = pageCount self

Good practices for Game Center matchData

*爱你&永不变心* 提交于 2019-12-01 10:36:02
I am new to GKTurnBasedMatch and i'm trying to figure out what are good practices for the "matchData" sent between players during turns. All the tutorials i've found mainly cover sending a string of text and I would like to send a lot more than that. It would be great if someone could pint me to a more advanced tutorial. An example of what I would like to do is a battle. The two players have their avatars and they have different details (health, attack, defence, etc), how should I send this data? The only way I see possible is to codify all the match details (a lot of them) into an

Good practices for Game Center matchData

烈酒焚心 提交于 2019-12-01 07:56:55
问题 I am new to GKTurnBasedMatch and i'm trying to figure out what are good practices for the "matchData" sent between players during turns. All the tutorials i've found mainly cover sending a string of text and I would like to send a lot more than that. It would be great if someone could pint me to a more advanced tutorial. An example of what I would like to do is a battle. The two players have their avatars and they have different details (health, attack, defence, etc), how should I send this

How to store an MKPolyline attribute as transformable in IOS coredata with swift?

偶尔善良 提交于 2019-12-01 04:15:27
What would be the code required to allow the storage of an MKPolyline in CoreData in swift. So for example if I had one of my core data entities (say "myEntity") for which I wanted to save an MKPolyline, and have added the "polyline" field as transformable, and have set it to "transformable" in xcode. Also have produced NSManagedObject subclass. myEntity.swift import UIKit import CoreData import MapKit class myEntity: NSManagedObject { } myEntity+CoreDataProperties.swift import Foundation import CoreData extension myEntity { @NSManaged var title: String @NSManaged var polyline: NSObject? }

NSCoding with Nested Custom Objects?

*爱你&永不变心* 提交于 2019-12-01 03:26:23
I have a series of nested objects that I am needing to put through the NSCoding protocol so that I can save the top level object into NSUserDefaults. Here is the structure of objects: 'Instructor' class NSMutableArray that holds instances of... 'Class' class NSMutableArray that holds instances of... 'Student' class Name Property Number Property Money Property I am needing to save an instance of Instructor to NSUserDefaults or to documents for the app. As you can see the Instructor object is holding an array that is then holding instances of a class. That class object is holding instances of

encodeWithCoder: unrecognized selector sent to instance [duplicate]

こ雲淡風輕ζ 提交于 2019-11-30 17:05:38
This question already has an answer here: How can I debug 'unrecognized selector sent to instance' error 9 answers I'm attempting use NSCoding protocol to read and write data to plist. I get an exception when I try to write the [GolfHoles] which is a subclass of NSObject. I've read several posts with different approaches, but none have helped. class GolfCourse: NSObject, NSCoding { var name: String = "" var location: String = "" var holes: [GolfHole] = [GolfHole]() init(holes: [GolfHole]) { self.holes = holes } // MARK: NSCoding Protocol func encodeWithCoder(aCoder: NSCoder) { aCoder

encodeWithCoder: unrecognized selector sent to instance [duplicate]

删除回忆录丶 提交于 2019-11-30 16:16:11
问题 This question already has answers here : How can I debug 'unrecognized selector sent to instance' error (9 answers) Closed 4 years ago . I'm attempting use NSCoding protocol to read and write data to plist. I get an exception when I try to write the [GolfHoles] which is a subclass of NSObject. I've read several posts with different approaches, but none have helped. class GolfCourse: NSObject, NSCoding { var name: String = "" var location: String = "" var holes: [GolfHole] = [GolfHole]() init

Does not conform to protocol 'NSCoding' - Swift 3

不问归期 提交于 2019-11-30 15:10:06
问题 I have seen several questions similar to mine; however, those are pertaining to swift 2/1 and I am currently using swift 3. I believe Apple has changed it slightly. class Person: NSObject, NSCoding { var signature: UIImage init(signature: UIImage) { self.signature = signature } required convenience init(coder aDecoder: NSCoder) { let signature = aDecoder.decodeObject(forKey: "signature") as! UIImage self.init(signature: signature) } func encodeWithCoder(aCoder: NSCoder) { aCoder.encode

Does not conform to protocol 'NSCoding' - Swift 3

纵饮孤独 提交于 2019-11-30 13:47:49
I have seen several questions similar to mine; however, those are pertaining to swift 2/1 and I am currently using swift 3. I believe Apple has changed it slightly. class Person: NSObject, NSCoding { var signature: UIImage init(signature: UIImage) { self.signature = signature } required convenience init(coder aDecoder: NSCoder) { let signature = aDecoder.decodeObject(forKey: "signature") as! UIImage self.init(signature: signature) } func encodeWithCoder(aCoder: NSCoder) { aCoder.encode(signature, forKey: "signature") } } You will notice how Swift 3 now forces me to use required convenience