I have some doubts about unsafe_unretained and weak keywords: as a read they are quite the same and the only difference is that the weak one is set to null if the pointed object is released.
Now I the code below and it crash at point [#2] during the [instanceOfTheView setDelegate:self]
but if in I4vMainView declaration [#1] I substitute
@property (nonatomic, weak) id <I4vDraggingFileProt> delegate;
with
@property (nonatomic, unsafe_unretained) id <I4vDraggingFileProt> delegate;
it works perfectly. What is the reason for this behavior? Thanks
Details: Target 10.7 compiling with ARC. Xcode 4.5.2 . Apple LLVM 4.1
In the class I4vMainView I have:
//----------- I4vMainView.h --------
@protocol I4vDraggingFileProt <NSObject>
-(void) anURLWasDeopped: (NSURL *) droppedUrl;
@end
@interface I4vMainView : NSView <NSDraggingDestination>{
NSImageCell *imageCell;
NSImage * image;
}
@property (nonatomic, weak) id <I4vDraggingFileProt> delegate; // [#1]
While in the caller
//----------- I4vViewController.h --------
@class I4vMainView;
@protocol I4vDraggingFileProt <NSObject>
-(void) anURLWasDeopped: (NSURL *) droppedUrl;
@end
@interface I4vViewController : NSViewController <I4vDraggingFileProt>{
I4vMainView * mv;
}
-(void) anURLWasDeopped: (NSURL *) droppedUrl;
@end
//----------- I4vViewController.m --------
@implementation I4vViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Initialization code here.
}
return self;
}
- (void)loadView{
mv = [[I4vMainView alloc] init];
[mv setDelegate:self]; // <-- [#2]
[self setView:mv];
}
-(void) anURLWasDeopped: (NSURL *) droppedUrl{
// ...
}
@end
Add:
With delegate declared as
@property (nonatomic, weak) id <I4vDraggingFileProt> delegate;
i have this Error
<I4vMainView: 0x10060bf40> objc[4773]: cannot form weak reference to instance (0x10061bf10) of class I4vViewController
and back-trace goes thoroughly _objc_trap <- objc_stroreWeak <- -[I4vMainView setDelegate:] <- [I4vViewController view]

I found the answer: as said in weak property for delegate cannot be formed