Sunday, 15 August 2010

ios - encoding either an int or NSInteger for state restoration -



ios - encoding either an int or NSInteger for state restoration -

i implementing state restoration in app. windows restored fine, trying encode properties of view controller related index used preserve state of view of view controller. have:

@property (nonatomic) int index; //prefer utilize int @property (nonatomic) nsinteger *testint; //i tried nsinteger , got same error code

and added next view controller .m file (also tried nsinteger, i'm pasting int code)

- (void)encoderestorablestatewithcoder:(nscoder *)coder { [coder encodeobject:self.index forkey:@"self.index"]; [super encoderestorablestatewithcoder:coder]; } - (void)decoderestorablestatewithcoder:(nscoder *)coder { self.index = [coder decodeobjectforkey:@"self.index"]; [super decoderestorablestatewithcoder:coder]; }

whether utilize int or nsinteger, same error message type these out (can't build)

for

[coder encodeobject:self.index forkey:@"self.index"];

the error message "incompatible integet pointer conversion sending 'int' parameter of type id."

and for

self.index = [coder decodeobjectforkey:@"self.index"];

the error "incompatible pointer integer conversion assigning 'int' 'id'"

clearly these errors 1 of same. there must way encode int, , if there isn't, why these errors when utilize nsinteger test int , replace above self.testint instead of self.index. in latter case, using pointer.

so question how encode either int (preferable) or nsinteger? give thanks you.

were trying utilize pointer integer '*testint'. think rather, 'testint'. , next able prepare error.

@property (nonatomic) int index; //prefer utilize int @property (nonatomic) nsinteger testint; //i tried nsinteger , got same error code - (void)encoderestorablestatewithcoder:(nscoder *)coder { [coder encodeint:self.index forkey:@"self.index"]; [super encoderestorablestatewithcoder:coder]; } - (void)decoderestorablestatewithcoder:(nscoder *)coder { self.index = [coder decodeintforkey:@"self.index"]; [super decoderestorablestatewithcoder:coder]; }

ios objective-c state-restoration

No comments:

Post a Comment