Reputation: 139
The point is for someone to enter their ClientID and API into two UITextField's and I'll pass them to a URL. Well I need to convert those to string. I have, but the app is crashing on running. What would be the best way to do this?
My code is below:
@interface LogInViewController : UIViewController
@property (strong, nonatomic) IBOutlet UITextField *clientID;
@property (strong, nonatomic) IBOutlet UITextField *clientAPI;
@end
@implementation LogInViewController {
NSString *clientIDToString;
NSString *clientAPIToString;
}
- (IBAction)signIn:(id)sender {
clientIDToString = _clientID.text;
clientAPIToString = _clientAPI.text;
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://api.digitalocean.com/droplets/?client_id=%p&api_key=%p", clientIDToString, clientAPIToString]];
}
Upvotes: 0
Views: 93
Reputation: 17697
First of all don't use %p
but use %@
in your string and so:
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://api.digitalocean.com/droplets/?client_id=%@&api_key=%@", clientIDToString, clientAPIToString]];
this is the reason of the crash.
Second thing: your @property
should be weak
and not strong
because you are using IBOutlet
.
Upvotes: 2
Reputation: 53112
This:
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://api.digitalocean.com/droplets/?client_id=%p&api_key=%p", clientIDToString, clientAPIToString]];
Should be:
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://api.digitalocean.com/droplets/?client_id=%@&api_key=%@", clientIDToString, clientAPIToString]];
Upvotes: 1