Initializing iOS Custom Object Error

I have a custom ProductCategory object.

.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 

This is an ordinary object, I have done it 100,000 times. The problem is that sometimes an 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 an instance of ProductCategory , and sometimes it returns "0 objects" , so I cannot assign any value to this object.

enter image description here

I think it must be something really stupid, but I don’t see it.

+6
source share
2 answers

Correction Method:

Restart Xcode.

Why is this happening?:

Apple must answer this question.

It seems that a memory issue in memory occurs after a while using Xcode.

Workarounds if you have a trap

@HotLicks is right about the recommendations for using NSLog and po to make sure the state of this object.

You can also call methods and read the properties of the object in question using the expression command in the debugger window after the breakpoint.

+4
source

zevarito is on the right track. A little more seems to solve a long annoying problem:

Close the project.

Xcode β†’ Window β†’ Projects For the project in question (and everyone else is probably a good cleaning idea), click Derived Data β†’ Delete.

Close Xcode. Close the simulator.

Restart Xcode and resume what you were doing.

0
source

Source: https://habr.com/ru/post/978124/


All Articles