Search code examples
iphonemethodsselectornsnotificationsnsnotificationcenter

Multiple Methods NSNotificationCenter iPhone


I have many methods that need the previous one to complete before firing the next one. I'm thinking I should NSNotificationCenter rather than performSelector afterDelay and just hope the method is done by that time.

Can someone map out how and where to add the notification to Method1, Method2 and Method3 where 1 needs to complete (not just fire) before 2 before 3.

Thanks


Solution

  • In general do not use notifications as method calls. They should be used to indicate that something did or will occur.

    From Apple's "Coding Guidelines for Cocoa":

    Notifications are identified by global NSString objects whose names are composed in this way:
    [Name of associated class] + [Did | Will] + [UniquePartOfName] + Notification
    For example:

    NSApplicationDidBecomeActiveNotification  
    NSWindowDidMiniaturizeNotification  
    NSTextViewDidChangeSelectionNotification  
    NSColorPanelColorDidChangeNotification