ios - How to call and use a function contained in another class file? -
i'm having strange problem, need call void
function called insertcommunication
contained in class file named mbuser.m
class, named prodottoviewcontroller.m
. since function not in prodottoviewcontroller
in mbuser.m
need step import class properly, correct me if i'm wrong:
import
.h
file ofmbuser
inprodottoviewcontroller.m
, this:#import "prodottoviewcontroller.h" #import "mbuser.h" @interface prodottoviewcontroller () { }
create
@class
ofmbuser
so:@class mbuser; /* class declaration placed between #import(s) , @interface of prodottoviewcontroller.m*/
create
@property
ofmbuser
inprodottoviewcontroller.m
@property (strong, nonatomic) mbuser *userclass;
alloc
,init
-alize mbuser, in case inviewdidload
function:- (void)viewdidload { [super viewdidload]; _userclass = [[mbuser alloc] init]; }
this code works, compiles , xcode gives me no error @ all, when try call function returns nil
[even other objects inside mbuser] if mbuser
correctly allocated can see here:
can please me?
edit: mbuser.m's init
method
- (id)init { self = [super init]; if (self) { dispatch_once(&oncetoken, ^{ dictcache = [[nsmutabledictionary alloc] init]; }); logined = no; allowlogin = yes; } return self; }
- you must nil userclass somehow. find out going on add dealloc method (
- (void)dealloc
) mbuser class , put there breakpoint check when it's being deallocated. - you don't need @class mbuser; in file in you've made import of class. @class forward declaring classes in header files.
Comments
Post a Comment