nscoder

UITableViewCell as UIView from XIB

霸气de小男生 提交于 2020-08-25 05:17:53
问题 I have CustomTableViewClass in XIB, adding it to UITableView like class RestaurantsTableView: UITableView { override func awakeFromNib() { self.register(UINib(nibName: "RestaurantTableViewCell", bundle: nil), forCellReuseIdentifier: "restaurantCell") } } and everything works fine, now I would like to use this CustomTableViewClass as UIView in some other UIViewController , but I do not get how to properly override its init(coder aCoder: NSCoder) function, cause I do not need one for

Swift Save viewcontroller state using coder beyond app close

早过忘川 提交于 2020-01-30 06:33:25
问题 I am using Xcode 8 and swift 2.3 I want to save the entire view controller to file and restore state even after app closes. I searched everywhere and found we need to use coder for that. but all just shows to save an object. but here I need to save entire ViewContoller and subviews. ViewCotroller will have three buttons Add Text Add Image : User can add any number of textViews and Images. So I need to save all that info also. Add ViewController : User may have an array of this viewController

Swift Save viewcontroller state using coder beyond app close

心不动则不痛 提交于 2020-01-30 06:32:31
问题 I am using Xcode 8 and swift 2.3 I want to save the entire view controller to file and restore state even after app closes. I searched everywhere and found we need to use coder for that. but all just shows to save an object. but here I need to save entire ViewContoller and subviews. ViewCotroller will have three buttons Add Text Add Image : User can add any number of textViews and Images. So I need to save all that info also. Add ViewController : User may have an array of this viewController

Save own Class with NSCoder

帅比萌擦擦* 提交于 2020-01-11 09:32:31
问题 I'm trying to store some custom class/data to a file in my iPhone/iPad app. I have a Class RSHighscoreList @interface RSHighscoreList : NSObject { NSMutableArray *list; } which contains objects of RSHighscore in the list @interface RSHighscore : NSObject { NSString *playerName; NSInteger points; } When I try to store all to file - (void)writeDataStore { RSDataStore *tmpStore = [[RSDataStore alloc] init]; _tmpStore.highscorelist = self.highscorelist.list; NSMutableData *data = [[NSMutableData

Save own Class with NSCoder

感情迁移 提交于 2020-01-11 09:32:09
问题 I'm trying to store some custom class/data to a file in my iPhone/iPad app. I have a Class RSHighscoreList @interface RSHighscoreList : NSObject { NSMutableArray *list; } which contains objects of RSHighscore in the list @interface RSHighscore : NSObject { NSString *playerName; NSInteger points; } When I try to store all to file - (void)writeDataStore { RSDataStore *tmpStore = [[RSDataStore alloc] init]; _tmpStore.highscorelist = self.highscorelist.list; NSMutableData *data = [[NSMutableData

Can NSManagedObject conform to NSCoding

为君一笑 提交于 2020-01-11 02:40:47
问题 I need to transfer a single object across device. Right now I am converting my NSManagedObject to a dictionary , archiving it and sending as NSData. Upon receiving I am unarchiving it. But I would really like to transfer the NSManagedObject itself by archiving and unarchiving instead of creating an intermediate data object. @interface Test : NSManagedObject<NSCoding> @property (nonatomic, retain) NSString * title; @end @implementation Test @dynamic title; - (id)initWithCoder:(NSCoder *)coder

'self' used before self.init call error while using NSCoding on a custom class

强颜欢笑 提交于 2019-12-25 07:19:28
问题 I'm trying to encode a custom class so I can save it using NSKeyedArchiver.archivedDataWithRootObject but when I try to conform to the NSCoding protocol, I get this error : 'self' used before self.init. Here is my code: class MemberRewardsInfo: NSObject, NSCoding { var id: Int? required convenience init?(coder aDecoder: NSCoder) { guard let unarchivedId = aDecoder.decodeObjectForKey("id") as? Int else { return nil } } func encodeWithCoder(aCoder: NSCoder) { aCoder.encodeObject(id, forKey: "id

When does initWithCoder get called?

∥☆過路亽.° 提交于 2019-12-23 09:29:54
问题 This will load an array - (id)initWithCoder:(NSCoder*) coder { self = [super initWithCoder: coder]; if (self) { myArray=[coder decodeObjectForKey:@"myArray"]; } return self; } What is the code that will call this function so that the array can be loaded? 回答1: The initWithCoder: methods are used for deserializing using NSCoding protocol, e.g. via [NSKeyedUnarchiver unarchiveObjectWithFile:]. For details see the Archives and Serializations Programming Guide, especially the Encoding and Decoding

Determine class while decoding object

亡梦爱人 提交于 2019-12-22 18:09:32
问题 For dealing with (a couple of) legacy communication protocols I try to subclass NSCoder . While the coding works fine, I have some issues with decoding: The protocol does not keep any type information, but a receiver "knows" the structure of a message. I wonder, how the decoder can determine which class an object (property) belongs to. For C types, this isn't really an issue because one can call decodeIntFromKey etc. But for objects one has to call decodeObject or decodeObjectForKey: . The

Swift - Why init(coder) is required in AFHTTPSessionManager?

吃可爱长大的小学妹 提交于 2019-12-22 18:08:32
问题 I'm not very experienced in iOS development. While making subclass of AFHTTPSessionManager XCode suggested me to include required init(coder) : import UIKit let _sharedAPIManager = APIManager(baseURL: NSURL(string: API_URL)!) class APIManager: AFHTTPSessionManager { /** * Singleton service * (https://github.com/hpique/SwiftSingleton) */ class var sharedInstance : APIManager { return _sharedAPIManager } init(baseURL url: NSURL!) { super.init(baseURL: url, sessionConfiguration: nil) self