ios - NSTimer userInfo Bad Access exception -


i got problem nstimer , userinfo.
in the docs apple writes system keeps strong reference timer (and therefore userinfo?) though when i'm trying access parts of userinfo object i'm getting bad access exception. (afaik means bad happened)

without further ado, here's how object looks pass userinfo:

@interface myobject  @property (nonatomic, assign) u_int8_t cmd; @property (nonatomic, assign) nsnumber *_id;  @end 

and here's how set timer:

nstimer *mytimer = [nstimer timerwithtimeinterval:10 target:self selector:@selector(somemethod:) userinfo:message repeats:no]; [[nsrunloop mainrunloop] mytimer formode:nsdefaultrunloopmode]; 

the method gets triggered when timer fires

-(void) somemethod:(nstimer *)timer{     myobject* mobject = [timer userinfo];     u_int8_t cmd = mobject.cmd; // works     nsnumber *_id = mobject._id; // bad access } 

note: userinfo isn't nil. neither u_int8_t nil or whatsoever. try access nsnumber object i'm receiving following exception (not every time):

crashed: com.apple.main-thread exc_bad_access kern_invalid_address @ 0x00000000 

what happens if add strong property nsnumber object? fix issue , why? why problem happen in first place?

as nsnumber object need use strong attribute, default, change @property declaration to:

@property (nonatomic) nsnumber *_id; 

and using _id identifier bad idea id objective-c keyword, , confuse @ point.


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -