If I want to reuse a protocol to notify the master view controller of when the detail view controller is dismissed such as this:
UIView notification when modal UIImagePickerController is dismissed?
where would i declare this protocol? Is it best practices to keep protocols in separate files? Thanks.
Typically I (copying Apple’s methods) declare protocols on the header of the class that will be interacting with delegates of that protocol. (E.g. the UIActionSheet header file holds the protocol declaration for UIActionSheetDelegate.) It doesn’t really matter technically where you declare protocols, as long as you don’t have a circular reference of
#importstatements. This won’t normally happen because the class that interacts with the protocol does so to avoid needing to#importall of the other classes that will now implement the protocol. (UIActionSheet sends messages to your classes when it is dismissed through the protocol, and therefore doesn’t need to #import any of your classes.)If you have a protocol and several unrelated classes will be interacting with delegates of that protocol, that would be a good indicator to put the protocol in its own file, because the protocol isn’t really associated with one particular class.