I have the following problem, because i just have started coding objective-c.
I have some instance with
@interface MyClass
@property (strong) MySecondClass *first;
@property (strong) MySecondClass *second;
@end
@implementation MyClass
@synthesize first = _first;
@synthesize second = _second;
/*this is called while initialisation*/
-(void) initialisation{
_first = [[MySecondClass alloc] init];
_second = [[MySecondClass alloc] init];
}
/*what i want to do*/
-(void) swap{
// second one should be replaced with first one
_second = _first;
// first pointer should be replaced by new instance
_first = [[MySecondClass alloc] init];
}
@end
Problem is, that when i call the swap method, the _first still points to the old object so _second will be replaced by same new object.
I already tried copy like follows, but it throws an exception.
_second = [_first copy];
PS: Im using ARC
Edit
What i really would like to accomplish, would be something like:
_second = _first
MySecondClass *tmp = [[MySecondClass alloc] init];
_first = &tmp;
But this shows compiler error: Implicit conversion of an indirect pointer to an Objective-C pointer to 'MySecondClass *' is disallowed with ARC
Thanks in advance.