Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Help with string format. Getting error: 'Use of undeclared identifier"

I am playing around with web services and can't get my string format correct for my SOAP request. I can't seem to get @%d to format correctly.

Here's my code:

 NSString *sSOAPMessage =[NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
                                            "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
                                                        "<soap:Body>"
                                                        "<postScore xmlns=\"http://tempuri.org\">"
                                                        "<score>"@"%d""</score>"
                                                        "<name>"@"%d""</name>"
                                                        "</postScore>"
                                                       "</soap:Body>"
                                                       "</soap:Envelope>",scoreInt,nameString] ;

1 Answer

if nameString is a string then you need to use %@, not %d. %d is for integers, %@ is for objects such as strings.

NSString *sSOAPMessage =[NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
                                            "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
                                                        "<soap:Body>"
                                                        "<postScore xmlns=\"http://tempuri.org\">"
                                                        "<score>"@"%d""</score>"
                                                        "<name>"@"%@""</name>"
                                                        "</postScore>"
                                                       "</soap:Body>"
                                                       "</soap:Envelope>",scoreInt,nameString] ;