I have an iOS 7 application that saves a custom object to app\'s iCloud Docs folder as a file. For this, I make use of NSCoding protocol.
@interface Person : NSO
newacct's answer helped me with the class name, but I also had an issue where I changed a variable name in my Swift class from my Objective-C class. Using @objc()
fixed that as well:
Old Class:
@interface JALProgressData : NSObject
@property (nullable, nonatomic, strong) NSString *platformID;
@property (nonatomic, assign) NSTimeInterval secondsPlayed;
@property (nonatomic, assign) NSTimeInterval totalDuration;
@property (nullable, nonatomic, strong) NSDate *lastUpdated;
@end
New Class:
@objc(JALProgressData)
class VideoProgress: NSObject, NSCoding {
@objc(platformID) var videoId: String?
var secondsPlayed: NSTimeInterval?
var totalDuration: NSTimeInterval?
var lastUpdated: NSDate?
}
I also realized I was using encodeObject
decodeObjectForKey
for value types, which was causing issues with my Swift class. Switching to encodeDouble
and decodeDoubleForKey
for the NSTimeInterval
types fixed aDecoder
returning nil
for those values.