I have a custom object ProductCategory
.
.h file:
#import <Foundation/Foundation.h>
@interface ProductCategory : NSObject
@property int productCategoryId;
@property NSString *name;
@property NSArray *children;
@property int parentCategoryId;
- (id)initWithId:(int)productCategoryId name:(NSString*)name;
- (id)initWithId:(int)productCategoryId name:(NSString*)name children:(NSArray*)chidren parentCategoryId:(int)parentCategoryId;
@end
.m file:
#import "ProductCategory.h"
@implementation ProductCategory
- (id)init {
if((self = [super init])) {
self.parentCategoryId = 0;
}
return self;
}
- (id)initWithId:(int)productCategoryId name:(NSString*)name {
if((self = [super init])) {
self.productCategoryId = productCategoryId;
self.name = name;
self.parentCategoryId = 0;
}
return self;
}
- (id)initWithId:(int)productCategoryId name:(NSString*)name children:(NSArray*)chidren parentCategoryId:(int)parentCategoryId {
if((self = [super init])) {
self.productCategoryId = productCategoryId;
self.name = name;
self.children = chidren;
self.parentCategoryId = parentCategoryId;
}
return self;
}
@end
It's just a normal object, I have done this 100000 times. The problem is, sometimes the instance of this object returns "0 objects"
and sometimes returns the correct object.
For example, if I do this ProductCategory *category = [[ProductCategory alloc]init];
sometimes it returns a ProductCategory
instance, and sometimes it returns "0 objects"
so I cannot assign any value to this object.
I guess it should be something really stupid but I don't see it.