Whats the difference between this:
@property (nonatomic, weak) id <SubClassDelegate> delegate;
and this:
@property (nonatomic, assign) id <SubClassDelegate> delegate;
I want to use property for delegates.
Whats the difference between this:
@property (nonatomic, weak) id <SubClassDelegate> delegate;
and this:
@property (nonatomic, assign) id <SubClassDelegate> delegate;
I want to use property for delegates.
The only difference between
weak
andassign
is that if the object aweak
property points to is deallocated, then the value of theweak
pointer will be set tonil
, so that you never run the risk of accessing garbage. If you useassign
, that won't happen, so if the object gets deallocated from under you and you try to access it, you will access garbage.For Objective-C objects, if you're in an environment where you can use
weak
, then you should use it.