Saturday, November 30, 2013

How to save the class string variable, solve, ask you

Created a new class
@ Interface WebConnect: NSObject
/ / / / / / User Information
@ Property (retain, nonatomic) NSString * userID;

- (Int) splitTableInfo: (NSString *) resData;
@ End

@ Implementation WebConnect
- (Int) splitTableInfo: (NSString *) resData
{
NSArray * array = [resData componentsSeparatedByString: @ "^"];

userID = [array objectAtIndex: 1];
checkedTableInfoData = true;
return 0;

}
There is a userID

Somewhere to declare an object of this class, and allocate space
pwebOperator = [[WebConnect alloc] init];


Then a string assigned to another userID

Follows
NSString * resTimerInfoData = [[NSString alloc] initWithData: XXXXX encoding: NSUTF8StringEncoding];
[PwebOperator splitTableInfo: resTimerInfoData];
[ResTimerInfoData release];

Then print userID value

NSLog (@ "% @", pwebOperator. UserID) ;/ / You can print it out, no problem

But I found that I added a Timer loop print this sentence would not be immediately agreed to the assignment after userID OK, this will be reported in the Timer inside userID does not exist
I will @ property (retain, nonatomic) NSString * userID; modified into @ property (copy) NSString * userID;

I would like to userID this value is stored in the class, how to do it, iphone really depressed below
Myself clear with another number, start again



Reply:
userID = [array objectAtIndex: 1]; init about this place. Value you are quoted, arguably the beginning you should not be able to print out. Memory management trouble ah.
Reply:
Timer in the main thread it?
Reply:
When Timer executed pwebOperator instances still there? Are executed in the main thread it?
Reply:
reference to the second floor of the reply:
Timer in the main thread it?

Yes, pwebOperator are still where I test it in pwebOperator added a bool value that still exists, it still can be printed po
Reply:
cited a floor reply:
userID = [array objectAtIndex: 1]; init about this place. Value you are quoted, arguably the beginning you should not be able to print out. Memory management trouble ah.

I can not have init each assignment once about it, again, and now I have at least 30 inside the class NSString * variable types, these data are dynamic changes, do all this out once every assignment, that does not bother the dead the ah
Reply:
Upstairs What are you saying? userID = [array objectAtIndex: 1]; reform userID = [[nsstring alloc] initwithstring [array objectAtIndex: 1]];

Do not change you study it slowly. Of course, the existence of a value type, nsstring is a reference type.
Reply:
self.userID = @ "";
To write this.
Directly userID = @ "" does not increase the reference count.
Reply:
reference to the 7th floor of replies:
self.userID = @ "";
To write this.
Directly userID = @ "" does not increase the reference count.


Thank you for your answer, I try
Reply:
references 6th Floor reply:
upstairs What are you saying? userID = [array objectAtIndex: 1]; reform userID = [[nsstring alloc] initwithstring [array objectAtIndex: 1]];

Do not change you study it slowly. Of course, the existence of a value type, nsstring is a reference type.

In this case, only the second re-assignment when I first release of the re-assignment of
Reply:
reference to the 7th floor of replies:
self.userID = @ "";
To write this.
Directly userID = @ "" does not increase the reference count.


Thank you for your answer, your answer is correct, I tried, thank, thank you for your reply

No comments:

Post a Comment