0

Im trying to to append a variable to a string but its showing an error. Im missing something ridiculously easy here but my mind is shot.

NSString *eID = [entertainmentArticle objectForKey:@"eID"];

NSURL *urla = [NSURL URLWithString:@"http://www.mydomain.com/iostest/appPHPs/schedule.php?eID=",eID];

3 Answers 3

3

You can't concat 2 string variables just by putting a comma between them. Try this instead:

NSURL *urla = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.mydomain.com/iostest/appPHPs/schedule.php?eID=%@",eID]];

Sign up to request clarification or add additional context in comments.

Comments

1

If all you are doing is appending, you have several options:

A. Use NSString & stringWithFormat:

NSString *eID = [entertainmentArticle objectForKey:@"eID"];
NSString *urlString = [NSString stringWithFormat:@"http://www.mydomain.com/iostest/appPHPs/schedule.php?eID=%@", eID];
NSURL *urla = [NSURL URLWithString:urlString];

B. Use NSString & stringByAppendingString:

NSString *eID = [entertainmentArticle objectForKey:@"eID"];
NSString *baseUrl = @"http://www.mydomain.com/iostest/appPHPs/schedule.php?eID=";
NSString *urlString = [baseUrl stringByAppendingString:eID];
NSURL *urla = [NSURL URLWithString:urlString];

C. Use NSMutableString & appendString:

NSString *eID = [entertainmentArticle objectForKey:@"eID"];    
NSString *baseUrl = @"http://www.mydomain.com/iostest/appPHPs/schedule.php?eID=";
NSMutableString *urlString = [NSMutableString stringWithString:baseUrl];
[urlString appendString:eID];
NSURL *urla = [NSURL URLWithString:urlString];

1 Comment

you should throw stringWithFormat: in the list
1

Try like this:-

NSString *eID = [entertainmentArticle objectForKey:@"eID"];

 NSString *url=@"http://www.mydomain.com/iostest/appPHPs/schedule.php?eID=";

NSURL *urla = [NSURL URLWithString:[url stringByAppendingString:eID];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.