0

I am facing a very weird issue. I create an object and I add it to a NSMutableArray but when I try to read it after I insert it, some subclasses of the object change to some weird classes like

PINGIFAnimatedImageManager

Here is the code I use to create the object and insert it to the NSMutableArray:

CustomContentGridRow *row = [[CustomContentGridRow alloc]init];
row.child1 = [dataManager getMapLocation]; // This is the MapLocation object that will change to this weird PINGIFAnimatedImageManager
row.useFullWidth=1;
row.index=0;
[arrCustomChilds addObject:row];

This is the CustomContentGridRow class:

@interface CustomContentGridRow : NSObject

@property (nonatomic, assign) MapLocation *child1;
@property (nonatomic, assign) MapLocation *child2;
@property (nonatomic, assign) int useFullWidth;
@property (nonatomic, assign) int index;

@end

So when I put a breakpoint at this line [arrCustomChilds addObject:hotelRow];, when I read the row object I get the expected results. But when I place a breakpoint after the above code to read the arrCustomChilds the class of child1 changes to some weird classes. Also, sometimes it won't change to another class but it will give nil values.

Any idea why this is happening?

3
  • 4
    You should change property modifier from "assign" to "strong" for class objects. Commented Feb 20, 2019 at 9:31
  • what is arrCustomChilds? Commented Feb 20, 2019 at 9:37
  • @kirander Yeap that's the answer. Please write it so I can accept it. Commented Feb 20, 2019 at 9:39

3 Answers 3

1

You should change property modifier from "assign" to "strong" for class objects. Otherwise undefined behaviour can happen.

Sign up to request clarification or add additional context in comments.

Comments

0

In Xcode -> Product -> Scheme - edit Scheme. Check the settings of RUN mode. If it is Release change to Debug.

This will give you the correct values

Change below properties

@property (nonatomic, strong) MapLocation *child1;
@property (nonatomic, strong) MapLocation *child2;

assign to strong

2 Comments

He's talking about breakpoins therefore obviously he is running in Debug.
You can add breakpoints in release mode too. But you wont see proper results as it is not a debug mode
0

Your interface should be:

@interface CustomContentGridRow : NSObject

@property (nonatomic, strong) MapLocation *child1;
@property (nonatomic, strong) MapLocation *child2;
@property (nonatomic, assign) int useFullWidth;
@property (nonatomic, assign) int index;

@end

the class objects should be strong not assign

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.