I create a Class with name and image. I use for loop to set NSMutableArray with set of object , The problem that after adding an object to the array the next round the array set the object to null as it remove the last object witch remove the object in the array here the code
#import "MiMAppDelegate.h"
@interface MiMAnimal : NSObject
@property (nonatomic,weak) NSString *name;
@property (nonatomic,strong) UIImage *image;
- (instancetype) initWithName:(NSString *)name
image:(UIImage *)image;
@end
@implementation MiMAnimal
-(instancetype)initWithName:(NSString *)name image:(UIImage *)image{
self =[super init];
if (self) {
_name = name;
_image = image;
}
return self;
}
- (NSString *)description {
return _name;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
NSMutableArray *Animals = [NSMutableArray array];
for (int i=1; i<30; i++) {
//after the first loop here the array contain 0 the object with null value !!
NSString *name =[[NSString alloc] initWithFormat: @"0%d",i ];
UIImage *image = [UIImage imageNamed:[[NSString alloc] initWithFormat: @"0%d.png",i ]];
NSLog(@"name : %@ ",name);
MiMAnimal *animal =[[MiMAnimal alloc]initWithName:name image:image];
[Animals addObject:animal];
//Here the animals array add the object
}
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}