reknab
reknab

Reputation: 405

Function Returning NSString Always Returns nil in iOS 4.2 SDK

The following code, while not necessarily pretty, worked absolutely fine in iOS 4.1 (returned an NSString with formatted HTML with the passed URL). In iOS 4.2.1, however, the function always returns nil if using stringWithFormat. NSLog shows the contents of embedHTML are correct, but the value of *html is always nil.

Any help is appreciated.

....
NSString *html = [self getHTML:urlString1];
....

- (NSString *)getHTML:(NSString *) url {

NSString *embedHTML = [NSString stringWithFormat:@"<html><head>\
<style type=\"text/css\">\
body {\
background-color: transparent;\
color: white;\
</style>\
</head><body style=\"margin:0\">\
<embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \
width=\"111\" height=\"116f\"></embed>\
</body></html>", url];

NSLog(@"Log: %@", embedHTML);

return embedHTML;

}

Upvotes: 0

Views: 1382

Answers (2)

TomSwift
TomSwift

Reputation: 39502

Put quotes around each split line. You shouldn't need the backslash.

This question is similar, for C++, but I think the same rules apply to Objective C

Splitting C++ Strings Onto Multiple Lines (Code Syntax, Not Parsing)

Upvotes: 0

ipraba
ipraba

Reputation: 16553

Try this

NSString *html = [NSString stringWithFormat:@"<html><head>\
                       <style type=\"text/css\">\
                       body {\
                       background-color: transparent;\
                       color: white;\
                       </style>\
                       </head><body style=\"margin:0\">\
                       <embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \
                       width=\"111\" height=\"116f\"></embed>\
                       </body></html>", urlString1];

Upvotes: 0

Related Questions