NYTom
NYTom

Reputation: 524

Objective C Converting a char * to a float and setting to a property

In my interface header file I have:

@proprty (readwrite, assign) float longitude;

If I assign a value to that property like this:

loc.longitude = [[NSString stringWithUTF8String:(const char *)attr->children->content] floatValue];

The debugger says [loc longitude] does not appear to point to a valid object.

but if I use

NSLog(@"%f", [[NSString stringWithUTF8String:(const char *)attr->children->content] floatValue]);

the float value is written.

What am I doing wrong, its like the value is not being assigned to the property?

Upvotes: 0

Views: 349

Answers (2)

rob mayoff
rob mayoff

Reputation: 385600

You said “The debugger says [loc longitude] does not appear to point to a valid object.”

I suspect that you are trying to use this debugger command:

po [loc longitude]

The problem is that [loc longitude] is indeed not an Objective-C object. It is a float. You need to use a different command to print it:

p (float)[loc longitude]

or, on a recent-enough version of Xcode/lldb, you can use the dot syntax directly:

p loc.longitude

Upvotes: 1

jtbandes
jtbandes

Reputation: 118671

Indeed, [loc longitude] is not an object. This means you can't use po in the debugger; use p instead.

Upvotes: 0

Related Questions