2010-12-02 6 views
0

Je semble avoir un problème avec le codage tring.Codage de chaîne de l'objectif C

Je le code suivant:

// Sets the server url and whether or not the server is logged in 
- (Server *) init:(NSString *) url { 

// Setup the singleton! 
_instance = self; 

// Store our own copy of the string 
self.serverUrl = [[NSString alloc] initWithString:url]; 
self.is_logged = NO; 
NSLog(@"Given: %s Current: %s Should BE: %s", url, self.serverUrl, @"http://clanware.com:8000/api"); 

return self; 
} 

`

L'objet est instancié comme suit:

self.server = [[Server alloc] init:@"http://clanware.com:8000/api"]; 
NSLog(@"URL in Server: %s", self.server.serverUrl); 

Je reçois la sortie suivante dans gdb (je suis en cela dans xcode)

[Session started at 2010-12-02 11:55:35 -0400.] 
2010-12-02 11:55:40.388 ProjectPrototype[1765:207] Given: `üô» Current: `üô» Should BE: `üô» 
2010-12-02 11:55:40.390 ProjectPrototype[1765:207] URL in Server: `üô» 

Toute aide serait appréciée, je suis perdu et je ne sais pas quoi faire!

Merci beaucoup =)

Répondre

0

vous ne devriez pas utiliser %s sur NSLog pour NSStrings.
Vous pouvez imprimer tout NSObject, y compris NSStrings, en utilisant %@ comme ceci:

NSLog(@"Given: %@ Current: %@ Should BE: %@", url, self.serverUrl, @"http://clanware.com:8000/api"); 
+0

Merci beaucoup cela a fonctionné parfaitement! –