Question

I'm declaring a lot of block types with typedef; is there any sort of naming convention for them?

Was it helpful?

Solution 2

See here in Apple's documentation, Enumerated constants and Naming Properties and Data Types

I can't really find anything in Apple's documenation, but I did fins one from AppCelerator.

OTHER TIPS

After doing a bunch of research, it seems that Apple doesn't typedef their blocks, and prefers to just name the parameters explicitly where they are used. Their Cocoa style guide also makes no mention of blocks being typedef'd.

For example, look at this method in NSURLSession.h from the NSURLSessionTaskDelegate:

- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task
                     willPerformHTTPRedirection:(NSHTTPURLResponse *)response
                                     newRequest:(NSURLRequest *)request
                              completionHandler:(void (^)(NSURLRequest * _Nullable))completionHandler;

Note that the completionHandler doesn't receive a typedef.

In my opinion, it only makes sense to typedef a block if the definition is immediately reusable, and is generic enough to be used in multiple places.

from Apple doc it's CamelCase with objective-C naming convention style (explicit/verbose)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top