Skip to content

Strange value is returned when "autoEncodeWithCoder"-method deals with NSInteger type #8

@TXF

Description

@TXF

Hi, greenisus. I very like your extension. But recently found a strange behavior. I tried to perform encoding operation with my class, where one of the field is NSInteger property:
@Property (nonatomic, assign) NSInteger userID;

I have noticed after encoding operation I got a wrong value in userID field. It contained 0 (in my case). I decided to deep into and found that actually I pass a correct number:12. Than - (void)autoEncodeWithCoder:(NSCoder *)coder is called.
This method gets Class properties and calls - (NSMutableDictionary *)propertiesForClass:(Class)klass {
Here I saw, that my NSInteger extracted via
NSString *pattrs = [NSString stringWithCString:property_getAttributes(property) encoding:NSUTF8StringEncoding];

and pattrs contains "Tq,N,V_userID"
I went to official documentation:https://developer.apple.com/library/mac/documentation/cocoa/conceptual/objcruntimeguide/articles/ocrtpropertyintrospection.html

And did not find specificator 'q'. Maybe apple has changed smith. But in your code you don't handle this 'q' case in your switch-case block in both methods:

  • (void)autoDecode:(NSCoder *)coder
  • (void)autoEncodeWithCoder:(NSCoder *)coder

you have case 'Q': // unsigned long long
but this 'q' do the same as case 'i': // int

when I added these cases, NSInteger encoding/decoding began work properly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions