mac
mac

Reputation: 4780

objective C string Confusion

I am having code

NSString *cellValue1 = [products1 objectAtIndex:indexPath.row];

when i try to print NSLog(@"cell value is %@",cellValue1);

in log i am not getting anything, if i use %s, i am getting some symbols, not the string located in cellValue1.

Please help me.

Thanks in advance.

Upvotes: 0

Views: 220

Answers (3)

Newbyman
Newbyman

Reputation: 1134

Solution:

NSString *cellValue1 = [products1 objectAtIndex:indexPath.row];
NSLog([NSString stringWithFormat:@"Cell Value is %@", cellValue1]);

Reason: NSLog operates with String inputs. While your statement should work, if there is some/any issue with your original cellValue1 string, your original statement will not catch the issue and assure that that NSLog() is being handed a pure string. By using the stringWithFormat: syntax you assure that even if your cellValue1 values is null or nil, you will receive your "cell value is" comment and possible some hint as to what is being passed into the statement by your cellValue1 string.

Testing Note: If the above doesn't work for you, Test your original string by just using NSLog(cellValue1);. If this doesn't work it will tell you that your original NSString is not properly pulling your product at indexPath.row values.

Hope this helps!

Upvotes: -1

Macmade
Macmade

Reputation: 54059

It surely means your string is empty... Check it with the length method...

Upvotes: 1

jlehr
jlehr

Reputation: 15617

Check to make sure that products1 is actually set. It sounds as though it's nil when you send it the -objectAtIndex: message.

Upvotes: 1

Related Questions