ios - NSSecureCoding in Swift (Facebook SDK) -


i trying translate objective-c piece of code swift code.

objective-c:

#import "sucacheitem.h"  #define sucacheitem_token_key @"token" #define sucacheitem_profile_key @"profile"  @implementation sucacheitem  + (bool)supportssecurecoding { return yes; }  - (id)initwithcoder:(nscoder *)adecoder { sucacheitem *item = [[sucacheitem alloc] init]; item.profile = [adecoder decodeobjectofclass:[fbsdkprofile class]   forkey:sucacheitem_profile_key]; item.token = [adecoder decodeobjectofclass:[fbsdkaccesstoken class] forkey:sucacheitem_token_key]; return item; }  - (void)encodewithcoder:(nscoder *)acoder { [acoder encodeobject:self.profile forkey:sucacheitem_profile_key]; [acoder encodeobject:self.token forkey:sucacheitem_token_key]; }  @end 

i translated piece of code this:

class cacheitem: nsobject, nssecurecoding {  let cacheitem_token_key = "token" let cacheitem_profile_key = "profile" var profile: anyobject var token: anyobject  func supportssecurecoding() -> bool {     return true }  required init(coder adecoder: nscoder) {     var item = cacheitem(coder: adecoder)     item.profile = adecoder.decodeobjectofclass(fbsdkprofile.self, forkey: cacheitem_profile_key)!     item.token = adecoder.decodeobjectofclass(fbsdkaccesstoken.self, forkey: cacheitem_token_key)! }   func encodewithcoder(acoder: nscoder) {     acoder.encodeobject(self.profile, forkey: cacheitem_profile_key)     acoder.encodeobject(self.token, forkey: cacheitem_token_key) }    } 

this giving me error: type 'cacheitem' not conform protocol 'nssecurecoding'

what missing here?

thanks in advance!

the supportssecurecoding function needs @ class level:

class func supportssecurecoding() -> bool {     return true } 

Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -