Actually, the problem is in
@property (nonatomic, copy) NSMutableArray* arrayOfObjects;
should be:
@property (nonatomic, strong) NSMutableArray* arrayOfObjects;
yeah? Thank,s for that guys!
I do not exactly understand how this bug worked, but I will try to get to know :)
I have trying to solve one problem since over an hour... I am afraid it is something very simple, but something I do not understand yet. I am guessing that this is something with memory management stuff cause this is my definitely weak point yet.
Post a little bit similar to 'Unrecognized selector sent to instance' and some others but they didnt solved my problem...
In a nutshell (pasting much cause don't know where the potential bug is):
@interface MyCustomObject : NSObject {
NSString* name;
int birthDate;
double heightInMeters;
}
@property(strong, nonatomic) NSString * name;
@property(nonatomic) int birthDay;
@property(nonatomic) double heightInMeters;
-(id)initWithDate:(int)birthDate
AndName:(NSString *)nameString
AndHeight:(double)h;
@end
//////////////////////////////////
#import "MyCustomObject.h"
@implementation MyCustomObject
@synthesize name;
@synthesize birthDay;
@synthesize heightInMeters;
-(id)initWithDate:(int)bd AndName:(NSString *)nameString AndHeight:(double)h{
if(self = [super init]){
self.birthDay = bd;
self.name = nameString;
self.heightInMeters = h;
return self;
}
return nil;
}
@end
And some kind of database for MyCustomObject
s:
DataCollection.h:
@interface DataCollection : NSObject{
NSMutableArray* arrayOfObjects;
}
@property (nonatomic, copy) NSMutableArray* arrayOfObjects;
-(void)addElement:(id)el;
@end
And implementation:
#import "DataCollection.h"
@implementation DataCollection
@synthesize arrayOfObjects;
-(id)init{
if(self = [super init]){
self.arrayOfObjects = [[NSMutableArray array] init];
NSLog(@"Number of record before init: %d", [self.arrayOfObjects count]);
[self addElement:[[MyCustomObject alloc] initWithDate:1988 AndName:@"Georg" AndHeight:1.88]];
[self addElement:[[MyCustomObject alloc] initWithDate:1951 AndName:@"Sebastian" AndHeight:1.58]];
NSLog(@"Number of record before init: %d", [self.arrayOfObjects count]);
return self;
}
return nil;
}
-(void)addElement:(id)el{
// UNRECOGNIZED SELECTOR ????
[self.arrayOfObjects addObject:el];
}
@end
Result is:
2013-03-05 15:42:56.826 XMLTest[11787:207] Number of record before init: 0 Current language: auto; currently objective-c 2013-03-05 15:43:51.446 XMLTest[11787:207] -[__NSArrayI addObject:]: unrecognized selector sent to instance 0x6816110
Do you see what I am doing wrong? I am guessing that this is something with memory management stuff