user597454
user597454

Reputation: 11

iPhone NSString problem

I'm using a var current_query to keep track of urls to load in my app. When I spec current_query with a static type string, i.e. current_query = @"hey"; It works to be expected, but when I start using dynamic values, such as.. current_query = [NSString stringWithFormat:@"hey%@",hey2]; I get weird results.. When I NSLog(@"%@",current_query);, I also get weird results like <1002f2c8 c0a8016a 00000000 00000000> Is it converting my string somehow? Whats going on here?

current_query is in my header file as NSString *current_query; and @property (nonatomic, retain) NSString *current_query; and then in my implementation file with @synthesize current_query;

Thanks all!

Upvotes: 0

Views: 221

Answers (2)

Kyle
Kyle

Reputation: 1672

Try fully allocating current_query first.
NSString current_query = [[NSString alloc] initWithString:@"hey"];
current_query = [NSString stringWithFormat:@"hey%@", hey2];
NSLog(@"%@", current_query);

also if hey2 is not an object and is instead a primitive like int, you cannot use %@. you have to use the appropriate string token.

Upvotes: -1

Wevah
Wevah

Reputation: 28242

Try setting the property instead of setting the instance variable directly:

self.current_query = NSString stringWithFormat:@"hey%@",hey2];

(Aside: currentQuery is the standard Obj-C naming convention.)

Upvotes: 4

Related Questions