nscoder

NSCoder: Unrecognized selector sent to instance

一个人想着一个人 提交于 2019-12-20 06:29:06
问题 So, I'm new to iOS and have been using online tutorials to learn the platform. The tutorials I'm using are building apps with iOS 9 while I'm using iOS 10. Because of that I have run into the title issue. Here is some code: CalendarEvent.swift class CalendarEvent : NSObject { var title : String var dateString : String init(withTitle t : String, andDateString ds : String) { title = t dateString = ds } init(withCoder coder : NSCoder) { dateString = coder.decodeObject(forKey: "dateString") as!

Simple Swift class does not compile

走远了吗. 提交于 2019-12-20 02:19:05
问题 My simple class, ClassWithOneArray, produces this error: Bitcast requires both operands to be pointer or neither %19 = bitcast i64 %18 to %objc_object*, !dbg !470 LLVM ERROR: Broken function found, compilation aborted! Command /Applications/Xcode6-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift failed with exit code 1 However, my class, ClassWithOneInt, does not. Why? class ClassWithOneInt { var myInt = Int() init(myInt: Int) { self.myInt = Int() } func

Easy way to do NSCoder enabled class

家住魔仙堡 提交于 2019-12-18 10:37:18
问题 I have tons of objects which I want to save for offline use. Currently I use create NSCoder compliant classes for the objects and coded data to file to be available offline. So in the .h I introduce the objects: @interface MyClass : NSObject<NSCoding>{ NSNumber* myObject;} @property(nonatomic,retain) NSNumber* myObject; And in .m I make the inits: - (id) initWithCoder: (NSCoder *)coder { if (self = [super init]) { [self setMyObject: [coder decodeObjectForKey:@"myObject"]]; } } - (void)

How do I encode enum using NSCoder in swift?

坚强是说给别人听的谎言 提交于 2019-12-17 04:00:28
问题 Background I am trying to encode a String-style enum using the NSCoding protocol, but I am running into errors converting to and back from String. I get the following errors while decoding and encoding: String is not convertible to Stage Extra argument ForKey: in call Code enum Stage : String { case DisplayAll = "Display All" case HideQuarter = "Hide Quarter" case HideHalf = "Hide Half" case HideTwoThirds = "Hide Two Thirds" case HideAll = "Hide All" } class AppState : NSCoding, NSObject {

How can I clone a NSCoding compliant object into a subclass of it?

瘦欲@ 提交于 2019-12-14 04:08:19
问题 I have a custom subclass of NSPopUpButtonCell so that I can overwrite its drawBezelWithFrame:inView: method. Currently, I have to create a fresh instance using initTextCell:pullsDown: and then copy all its properties by hand. That's rather tedious and error-prone as I may be missing some properties. I wonder if I can use initWithCoder: for this task instead. I imagine I should be able to file the data from the existing NSPopUpButtonCell instance into an NSCoder object, e.g. into

iOS - Locally saving an array of key value pairs

杀马特。学长 韩版系。学妹 提交于 2019-12-13 02:38:34
问题 In an app I'm developing the user needs to add an "enterprise" to use the app. However, they can add more than one "enterprise" to the app. Every enterprise added needs two things: a name, and an enterprise API key. I have created an "Enterprise" class: class Enterprise : NSObject { var name:String! var apiKey:String! init (name:String, apiKey:String) { self.name = name self.apiKey = apiKey } required init(coder decoder: NSCoder) { self.name = decoder.decodeObjectForKey("name") as String self

Trouble decoding with NSKeyedUnarchiver

℡╲_俬逩灬. 提交于 2019-12-11 03:42:37
问题 I am writing an app targeted at iOS 4.0 on XCode 3.2.3 where I store some data when the app closes using NSCoder protocol. Saving seems to work fine, the problem is retrieving the data from the saved files. My save method looks like this: -(void)saveMusicalWorksToMemory{ // create the save paths NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *mwPath = [documentsDirectory

-[_SwiftValue encodeWithCoder:]: unrecognized selector sent to instance

荒凉一梦 提交于 2019-12-10 12:45:30
问题 Getting error when trying to utilize NSCoder Player.swift: class Player: NSObject, NSCoding { private var _playerName: String! private var _playerScore: Int! private var _playerColor: PlayerColor! //PlayerColor is an enum var playerName: String { get { return _playerName } set { _playerName = newValue } } var playerScore: Int { get { return _playerScore } set { _playerScore = newValue } } var playerColor: PlayerColor { get { return _playerColor } set { _playerColor = newValue } } init

NSCoder and custom types

老子叫甜甜 提交于 2019-12-10 03:43:39
问题 How do you use NSCoder to encode and decode custom types? For example, how would you use NSCoder with an instance of " STATE " where: typedef enum { ON, OFF } STATE; 回答1: You can treat them as integers as they are implicitly assigned integer values: - (void) encodeWithCoder: (NSCoder *)coder { ... [coder encodeInt:type forKey:@"state"]; } - (id) initWithCoder: (NSCoder *)coder { ... state = [coder decodeIntForKey:@"state"]; } 来源: https://stackoverflow.com/questions/4029760/nscoder-and-custom

NSUserDefaults, NSCoder, Custom Class - iPhone app question

☆樱花仙子☆ 提交于 2019-12-08 14:44:10
问题 I'm having an error and I guess I'm doing something wrong in the following process. Firstly, I have a class Contacts: @interface Contact : NSObject<NSCoding> { @private ABRecordRef ref; NSString *first; NSString *last; bool selected; NSString *phoneNumber; } And in Contact's implementation, I have: - (void)encodeWithCoder:(NSCoder *)encoder { [encoder encodeObject:first forKey:@"First"]; [encoder encodeObject:last forKey:@"Last"]; [encoder encodeObject:[NSNumber numberWithInteger: