Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAHMET GÜLERER
1,597 PointsWhy still weak reference is there???
Please look at the code and tell me why weakArray is still there?
import <Foundation/Foundation.h>
@interface clsAhmet : NSObject
@property (nonatomic,weak) NSArray *weakArray; @property (nonatomic,strong) NSArray *strongArray;
-(void) calis;
@end
import "clsAhmet.h"
@implementation clsAhmet
-(void) calis
{ self.strongArray = @[@"strongArray1",@"strongArray2"];
self.weakArray = self.strongArray;
self.strongArray = nil;
if(self.weakArray != nil)
{
NSLog(@"weakArray halen nil degil");
}
}
@end
output:
2014-06-25 01:03:52.545 StrongvsWeak[2216:303] weakArray halen nil degil Program ended with exit code: 0
2 Answers
Alaattin CATE
2,865 PointsYou should use this code
self.weakArray = [[NSArray alloc] initWithArray:self.strongArray];
Instead of this code
self.weakArray = self.strongArray;
AHMET GÜLERER
1,597 PointsThanks for answer. That is useful.