tags:

views:

365

answers:

3
NSString *tmpStr = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
xmlSms = [xmlSms stringByAppendingString:tmpStr];
NSLog(xmlSms);

I got code above but NSLog doesn't show anything... Anybody know the problem??

+3  A: 

Your call to NSLog is not correct. Try:

NSLog(@"%@", xmlSms);
fbrereto
To expand, `%@` is the format specifier for an object in the `NSLog()` format string, which applies to `NSString` instances since they are objects. The string format specifiers are explained here: http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html#//apple_ref/doc/uid/TP40004265
Perspx
It is not the issue, I already check the xmlSms length and it showed 0. And nslog(xmlsms) Should be worked too as Ive did it many time. The problem is why appendingstring doesn't worked
How do you create xmlSms? Can you show the code for that variable?
fbrereto
A: 

In Cocoa, initialization functions ("constructors") often return nil if they fail for some reason or another. The documentation for NSString states:

Returns nil if the initialization fails for some reason (for example if data does not represent valid data for encoding).

Are you sure the NSData object passed to the init function actually contains a UTF8-encoded string? If it doesn't, the returned object will be nil.

mipadi
Yes, NSString *tmpStr = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];Is that what you mean?I think the problem is about this, xmlSms = [xmlSms stringByAppendingString:tmpStr];But i can't figure out why it doesn't worked..
A: 

nevermind... i figured out why. The problem is, when you want to use stringByAppendingString on a string, the string should have initial value.

Wrong example: NSString *str1; str1 = [str1 stringByAppendingString=@"test"]; Should be: NSString *str1 = @""; str1 = [str1 stringByAppendingString=@"test"];