I am getting this error:
exc_bad_access (code=1, address=0x2012
when I try to receive a value from a singleton in this way:
Draggable* sharedSingleton = [Draggable sharedManagerDraggable];
NSLog(@"%@", sharedSingleton.namePassedToDraggable);
The code above is placed in the Draggable.m of type UIImageView, which also has:
+ (Draggable *)sharedManagerDraggable
{
static Draggable *sharedManagerDraggable = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedManagerDraggable = [[Draggable alloc] init];
});
return sharedManagerDraggable;
}
I assign a value to namePassedToDraggable in this way (from view controller.m):
#import Draggable.h
Draggable* sharedSingleton = [Draggable sharedManagerDraggable];
sharedSingleton.namePassedToDraggable = txt.text;
NSLog(@"%@", sharedSingleton.namePassedToDraggable);
dragger.tag = img.tag;
And in Draggable.h I have:
+ (Draggable *) sharedManagerDraggable;
@property (nonatomic, assign) NSString* namePassedToDraggable;
Why do I get the error causing the app to crash? I use the same method in other viewcontorllers and it works just fine!
should be
If the property is not
strong, it’s not retained and it’s released at the end of the scope of the function in which you’re assigning it.