I am creating one application in iOs 5 using story board and in that application I need to use one NSMutableArray for table View.
so I am creating that array as shown below.
but in iOs 4 we creating array like
@interface MySpots : UITableViewController{
NSMutableArray *MySpots;
}
@property (nonatomic, strong) NSMutableArray *MySpots;
and in .m file
@synthesize MySpots;
- (void)viewDidLoad
{
[super viewDidLoad];
MySpots = [[NSMutableArray alloc]init];
for (int i = 0; i<10; i++) {
mySpot.SpotName = @"Name Of Spot";
mySpot.SpotTime = @"15mi";
mySpot.SpotDis = @"Short preview of the description will appear in this section.Acts as a reminder for relevant";
[MySpots addObject:mySpot];
}
}
but when i try to do this in iOs 5 it will show me error(“Expected identifier or {” ) on
MySpots = [[NSMutableArray alloc]init];
because in iOs 5 no need to release. so how should i have to declare NSMutableArray in iOs 5 .
thanks in advance 🙂
This has nothing to do with iOS 5 but rather is a compiler error from objective C. The basic problem is that you use
MySpotsboth as interface name and as property/instance variable. When encountering your linethe compiler now is unsure if this is the variable
MySpotsor should be a declaration of a variable of typeMySpots, e.g.The compiler assumes the second and bails out because of the missing variable name.
You should
self.property =instead ofproperty =because this uses the correct memory management. ARC somewhat reduces this problem but it is good practice anyway to use the automatic retain/release provided by properties.Either one of those would help (in case 1 the compiler now is clear on what to do, in case 2
self.MySpotswould be a unique name and could not be mixed up with the class name) but I would definitely do both, rename the property (or class) and useself.property =.PS: Even with ARC you still initialize as usual by using
[[NSMutableArray alloc] init]ARC just inserts the appropriateretainandreleasesbehind the scenes.