Strange NSString Behavior
Strange NSString Behavior
- Subject: Strange NSString Behavior
- From: Kenneth Ramey <email@hidden>
- Date: Wed, 25 Feb 2009 22:58:40 -0700
I have a method, written in Objective-C, to parse a string, extracting
several fields from it. Originally, I was pulling out a couple of
float values and some int fields. Other fields in the string need to
be treated as substrings. As I researched how to deal with the
substrings, I came to the conclusion that it might be easier to treat
all of the fields as substrings. So I re-wrote the method to use
NSString variables for each of the fields extracted from the main
string by an instance of NSScanner.
Now, when I run my program, I get the following error on the console
when execution enters the method in question:
Did you forget to nest alloc and init?
This message is repeated different numbers of time each execution. By
commenting out various parts of the code and using the debugger to
examine variables I find that one or more of the NSString variables
are actually listed as NSPlaceholderString variables and there is a
direct correlation between the number of "...Placeholder..." variables
and the number of messages that are printed. If I comment out all the
NSString variables, the messages go away. Which variables appear to
be "...Placeholder..." variables also changes on each execution.
Here is the fragment of code in question. The basic template came
from an Apple example of using NSScanner:
- (void) processFixRecord:(NSString *) dataString
{
NSString *fixTime;
NSString *fixLat;
NSString *fixLong;
NSString *northSouth;
NSString *eastWest;
NSCharacterSet *skipSet = [NSCharacterSet
characterSetWithCharactersInString:@" ,\n"];
NSScanner *dataRecord = [[NSScanner alloc] initWithString:dataString];
[dataRecord scanUpToCharactersFromSet:skipSet intoString:&fixTime];
...
Anyone have any suggestions? I also tried doing "alloc" and "init" on
each NSString (despite the Apple NSScanner example) with no change in
behavior and setting each variable to "nil", which also produced no
change.
Thanks.
-------------------------------
Ken Ramey
email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden