Using Block in Objective C by example

Overview Say we have a class called SPFPriceFetcher that uses JCDHTTPConnection. SPFPriceFetcher | |—JCDHTTPConnection JCDHTTPConnection uses NSURLConnection connection where any data, finish loading, or response received would have to give feedback BACK to SPFPriceFetcher. We give feedback by retaining and using block definitions passed in from SPFPriceFetcher. Passing block definitions from parent (SPFPriceFetcher) to child […]

copy and mutableCopy of NSMutableString

For NSMutableString AND NSString say we have:

If you use

it will return you an immutable object (NSString*) with its own address. This means you cannot change the data. Hence, even if you declare a NSMutableString pointer, and use setString to change the data, the compiler will give you an exception.

if […]

Shallow and deep copy of NSArray

copying NSArray If we are to use [NSArray copy]. The source array and copy array are pointing to the same address. If we are to use [NSArray mutableCopy]. The source array and copy array have created their own NSArray, and thus have different addresses. However, the User pointers inside the copy array points to the […]

implementing NS Copying

REF: User.m

Objective C – Apple Mach – O Linker Error

It means you are missing a framework. Look for the method name in the error. In my case it was some CAAnimation call used by a class. CAAnimation is used by the framework QuartzCore. Hence by adding QuartzCore framework, I solved this issue.

NSNotification addObserver object differentiation

In your init

what to do when the message is sent

Sending the message

When adding observers to receive notifications for a certain unique id, we can choose which object to receive it from. In our example below, we have method sexGroupUpdated: which will be executed once the notification is received for […]


dispatch_async vs dispatch_sync

ref: xCode 7.3 sample code The main reason why you want to use concurrent or serial queues over the main queue is to run tasks in the background. Sync on a Serial Queue dispatch_sync – 1) dispatch_sync means that the block is enqueued and will NOT continue enqueueing further tasks UNTIL the current task […]