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 t开发者_运维百科ype 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!
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.)
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.
精彩评论