What happens if I don’t retain IBOutlet?

It is recommended you declare properties for all of your IBOutlets for clarity and consistency. The details are spelled out in the Memory Management Programming Guide. The basic gist is, when your NIB objects are unarchived, the nib loading code will go through and set all of the IBOutlets using setValue:forKey:. When you declare the … Read more

Non-retaining array for delegates

I found this bit of code awhile ago (can’t remember who to attribute it to). It’s quite ingenius, using a Category to allow the creation of a mutable array that does no retain/release by backing it with a CFArray with proper callbacks. @implementation NSMutableArray (WeakReferences) + (id)mutableArrayUsingWeakReferences { return [self mutableArrayUsingWeakReferencesWithCapacity:0]; } + (id)mutableArrayUsingWeakReferencesWithCapacity:(NSUInteger)capacity { … Read more

Objective-C 101 (retain vs assign) NSString

There’s no such thing as the “scope of an object” in Objective-C. Scope rules have nothing to do with an object’s lifetime — the retain count is everything. You usually need to claim ownership of your instance variables. See the Objective-C memory management rules. With a retain property, your property setter claims ownership of the … Read more

@property definitions with ARC: strong or retain?

1) Shouldn’t retain now be replace with strong or weak? No. You cannot replace retain with weak; they are different. And strong is a 100% synonym for retain; they are identical. You can use either, so there is no “should” here. You can replace retain with strong if you like, but you don’t have to. … Read more

Fix warning “Capturing [an object] strongly in this block is likely to lead to a retain cycle” in ARC-enabled code

Replying to myself: My understanding of the documentation says that using keyword block and setting the variable to nil after using it inside the block should be ok, but it still shows the warning. __block ASIHTTPRequest *request = [[ASIHTTPRequest alloc] initWithURL:… [request setCompletionBlock:^{ NSDictionary *jsonDictionary = [[CJSONDeserializer deserializer] deserialize:request.responseData error:nil]; request = nil; // …. … Read more

capturing self strongly in this block is likely to lead to a retain cycle

The capture of self here is coming in with your implicit property access of self.timerDisp – you can’t refer to self or properties on self from within a block that will be strongly retained by self. You can get around this by creating a weak reference to self before accessing timerDisp inside your block: __weak … Read more

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