Calling [self methodName] from inside a block?

Yes, you can do this. Note, however, that the block will retain self. If you end up storing this block in an ivar, you could easily create a retain cycle, which means neither would ever get deallocated. To get around this, you can do: – (void) someMethodWithAParameter:(id)aParameter { __block MySelfType *blocksafeSelf = self; void (^tempFunction)(void) … Read more

What is the difference between a __weak and a __block reference?

From the docs about __block __block variables live in storage that is shared between the lexical scope of the variable and all blocks and block copies declared or created within the variable’s lexical scope. Thus, the storage will survive the destruction of the stack frame if any copies of the blocks declared within the frame … Read more

Blocks instead of performSelector:withObject:afterDelay: [duplicate]

There’s no built-in way to do that, but it’s not too bad to add via a category: @implementation NSObject (PerformBlockAfterDelay) – (void)performBlock:(void (^)(void))block afterDelay:(NSTimeInterval)delay { block = [[block copy] autorelease]; [self performSelector:@selector(fireBlockAfterDelay:) withObject:block afterDelay:delay]; } – (void)fireBlockAfterDelay:(void (^)(void))block { block(); } @end Credit to Mike Ash for the basic implementation.

Alternatives to dispatch_get_current_queue() for completion blocks in iOS 6?

The pattern of “run on whatever queue the caller was on” is appealing, but ultimately not a great idea. That queue could be a low priority queue, the main queue, or some other queue with odd properties. My favorite approach to this is to say “the completion block runs on an implementation defined queue with … Read more

When to use enumerateObjectsUsingBlock vs. for

Ultimately, use whichever pattern you want to use and comes more naturally in the context. While for(… in …) is quite convenient and syntactically brief, enumerateObjectsUsingBlock: has a number of features that may or may not prove interesting: enumerateObjectsUsingBlock: will be as fast or faster than fast enumeration (for(… in …) uses the NSFastEnumeration support … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)