我需要在目標c中創建可中斷的掛鉤。如果任何掛鉤回調中斷操作,可中斷掛鉤應該能夠中止操作。我想用NSNotificationCenter
爲喜歡的:我可以更改通知中的用戶信息
NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
[userInfo setObject: [NSNumber numberWithBool: NO] forKey: @"interrupted"];
[notificationCenter postNotificationName: @"Operation A will happen"
object: self userInfo:userInfo];
if(![[userInfo objectForKey: @"interrupted"] boolValue])
{
[self doOperationA];
}
和鉤側
-(void) operationAWillHappen: (NSNotification *) note
{
if(someCondition)
[(NSMutableDictionary *)note.userInfo setObject:
[NSNumber numberWithBool: YES] forKey: @"interrupted"];
}
我能否改變這樣的用戶信息?有沒有更好的方法在目標c中實現可中斷的鉤子?