ios - How can I write completion block with nullable? -


when call method nil, app crashes, want know how write nullable.

crash

 [kptaxnoteapisavehandler saveentrywithuuid:uuid completion:nil]; 

ok

 [kptaxnoteapisavehandler saveentrywithuuid:uuid completion:^(nserror *error) {}]; 

this code.

+ (void)saveentrywithuuid:(nsstring *)uuid completion:(void (^ __nullable)(nserror * _nullable error))completion {      nslog(@"saveentrywithuuid");      entry *entry = [entry mr_findfirstbyattribute:@"uuid" withvalue:uuid];      nsdictionary *params = @{@"entry[uuid]":entry.uuid};      [kptaxnoteapisavehandler postwithurl:kapiurlstringforentry params:params completion:^(nserror *error) {          if (!error) {              [magicalrecord savewithblock:^(nsmanagedobjectcontext *localcontext) {                  entry *entry    = [entry mr_findfirstbyattribute:@"uuid" withvalue:uuid incontext:localcontext];                 entry.needsave  = @no;             }];         }          completion(error);     }];  + (void)postwithurl:(nsstring *)urlstr params:(nsdictionary *)params completion:(nullable void (^)(nserror *_nullable error))completion {      afhttprequestoperationmanager *manager = [afhttprequestoperationmanager manager];      [manager post:urlstr parameters:params success:^(afhttprequestoperation *operation, id responseobject) {          completion(nil);      } failure:^(afhttprequestoperation *operation, nserror *error) {          completion(error);     }]; 

where crash happening? first guess need this:

if (completion) {     completion(nil); // or completion(error); } 

this handle case completion nil.


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -