-1

My IOS app needs to put a number behind a string. The number is received by the index of the cell that is being pushed. however if i run the app and push a cell. My screen goes to xCode showing that there is a variable called tempstring. the simulator however does not respond anymore.. How can i fix this? This is the code i use:

    -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *tempstring = [NSString stringWithFormat: @"http://www.app-creater.com/service.php?k=%i",indexPath.row];
    NSLog(tempstring);
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Retrieve cell
    NSString *cellIdentifier = @"BasicCell";
    UITableViewCell *myCell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    // Get the location to be shown
    Location *item = _feedItems[indexPath.row];

    // Get references to labels of cell
    myCell.textLabel.text = item.Name;

    return myCell;
}

I get a thread 1: breakpoint 1.1 at the NSlog(tempstring) Saying incomplete format specifier.

How can i fix this?

-EDIT-

What i want to achieve is to get the string: "www.app-create.com/service.php?k=1" (or any number) with that string i want to download a partial JSON piece so in example the Password piece, corresponding to the string number. so for example that link is for the email address: tet@icloud.com, i get the password 1234, for the link www.app-create.com/service.php?k=0, i get password 4321

brian
  • 156
  • 1
  • 1
  • 11
  • That's two different things, a breakpoint and a compiler warning. Fix the compiler warning and remove the breakpoint. – jscs Apr 17 '14 at 18:50
  • Thanks... i don't know what happened. Rookie mistake >.>' – brian Apr 17 '14 at 19:12
  • This question is similar to the “Thread 1: stopped at breakpoint” error when initializing an NSURL object. – brian Apr 18 '14 at 13:44

3 Answers3

1

You can't use NSLog without format specifier.

Change :

NSLog(tempstring);

to

NSLog(@"%@",tempstring);

According to this apple documentation, your code may crash due to signal 10 (SIGBUS)

Midhun MP
  • 103,496
  • 31
  • 153
  • 200
  • Of course you can, if `tempstring` does not contain any `%` format specifiers. (That does not mean that you should.) – Martin R Apr 17 '14 at 18:55
  • Even when changing it it does not work. i also removed the NSLog(), and it stil freezes up. i think it has something to do with declaring a variable – brian Apr 17 '14 at 19:02
  • @MartinR: If I'm wrong please let me know the answer. According to this [documentation](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Functions/Reference/reference.html) NSLog calls NSLogv it expects a format specifier. – Midhun MP Apr 17 '14 at 19:02
  • If I see it correctly, `tempstring` is computed as (for example) `@"http://www.app-creater.com/service.php?k=5"`. Then `NSLog(temp string)` will work. It would crash if `tempstring` contained any `%` characters which NSLog would try to replace by (non-existing) arguments). – Martin R Apr 17 '14 at 19:11
  • You are completely right that you *should* always use `NSLog(@"%@",temp string);`. I just don't see how this would cause a crash in this particular question. – Martin R Apr 17 '14 at 19:12
  • @MartinR: I mainly concentrated on the following part of the question `NSlog(tempstring) Saying incomplete format specifier.` – Midhun MP Apr 17 '14 at 19:14
  • That's fine, and as it seems, there was no crash at all, only a breakpoint and a compiler warning. But *"your code will cause a crash ..."* is wrong. It causes the warning, and it *might* crash, depending on what tempstring contains. – Martin R Apr 17 '14 at 19:16
  • @MartinR: Yeah, you are correct. – Midhun MP Apr 17 '14 at 19:20
1

The definition of NSLog is as fellows:

FOUNDATION_EXPORT void NSLog(NSString *format, ...) NS_FORMAT_FUNCTION(1,2);

So you can't write a statement like:

NSLog(tempstring);  

You always need to use a format string and pass in the arguments that you want - to be part of the NSString like following:

NSLog(@"The value of tempstring is: %@", tempstring); 
Arslan Ali
  • 17,418
  • 8
  • 58
  • 76
-1

Not sure '%i' is a valid format specifier. you might have to use '%d' or one of the ones specified here

https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html#//apple_ref/doc/uid/TP40004265-SW1

one stevy boi
  • 577
  • 6
  • 24