开发者

Issue with member of custom object

开发者 https://www.devze.com 2023-02-15 03:34 出处:网络
I have a custom class @interface XYZ : NSObject { int sum; .... } 开发者_如何学运维@property (nonatomic, assign) int sum;

I have a custom class

@interface XYZ : NSObject 

{ int sum; .... }

开发者_如何学运维

@property (nonatomic, assign) int sum; .....

In my method, I initialize a new class as:

XYZ *myClass = [[XYZ alloc] init];

Then in a for loop in that method, I assign the value of sum based on a condition:

if(   )

{ myClass.sum = val;

NSLog(@"%d", myClass.sum); }

The NSLog prints the correct value. (The value here is = 6)

Now, once I am out of the for loop, I again print the value of sum using the same NSLog statement:

NSLog(@"%d", myClass.sum);

This time the value is 0. I never understood why. Thinking that the value was not retained, I even used the NSString and NSNumber data types but I have not had any success.

Is it something very basic I am missing? Please advice.

Thanks for any help in advance


Thanks for your quick replies but I have found the issue.

I trusted the external data to only have a single value for "sum" but there was a duplicate and this was set to zero.

I am using int, NSString and NSNumber data types as per documentation.

It's ok now.

Thanks again for your help.

Subbu

0

精彩评论

暂无评论...
验证码 换一张
取 消