ios - Making a method -


how make method accepts object of type nsarray called objects , can called different view controllers such last method called savecontext?

//save core data  coredatastack *coredatastack = [coredatastack defaultstack]; leanmessage *message = [nsentitydescription insertnewobjectforentityforname:@"leanmessage" inmanagedobjectcontext:coredatastack.managedobjectcontext];  (nsdictionary *lean in objects) {             [message setvalue:[lean objectforkey:@"objectid"] forkey:@"objectid"];     [message setvalue:[lean objectforkey:@"senderid"] forkey:@"senderid"];     [message setvalue:[lean objectforkey:@"recipientid"] forkey:@"recipientid"];     [message setvalue:[lean objectforkey:@"messagebody"] forkey:@"body"];     [message setvalue:[lean objectforkey:@"timestamp"] forkey:@"timestamp"];     }  [coredatastack savecontext]; 

.h file

@interface ...  ... - (void)mymethod: (nsarray *)objects;  @end 

.m file

- (void)mymethod: (nsarray *)objects {     coredatastack *coredatastack = [coredatastack defaultstack];     leanmessage *message = [nsentitydescription insertnewobjectforentityforname:@"leanmessage" inmanagedobjectcontext:coredatastack.managedobjectcontext];      (nsdictionary *lean in objects){         [message setvalue:[lean objectforkey:@"objectid"] forkey:@"objectid"];         [message setvalue:[lean objectforkey:@"senderid"] forkey:@"senderid"];         [message setvalue:[lean objectforkey:@"recipientid"] forkey:@"recipientid"];         [message setvalue:[lean objectforkey:@"messagebody"] forkey:@"body"];         [message setvalue:[lean objectforkey:@"timestamp"] forkey:@"timestamp"];     }      [coredatastack savecontext]; } 

if want access class , if current class's name myclass, in class want access it, following:

nsarray *anotherarray = ... myclass *thisclass = [[myclass alloc] init]; [thisclass mymethod:anotherarray]; 

hope answers question. :)


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -