开发者

IPhone Float to String issue

I can't live another day without knowing why this is happening. I have an iPhone application using Corelocation and here is the issue:

GPSLocation.m - sends long/lat coordinates which are floats to class UserSettings.m (which is a singleton class)

_

UserSettings.m - Then cast the values into a predefined strings from a float

e.g. strLongitude = [NSString stringWithFormat:@"%f", paramLong];

I can trace out the string just fine NSLog(@"Longitude string is %@", strLongitude);

Some notes about strLongitude

  1. is in the header file
  2. property is defined as (nonatomic, retain)
  3. is synthesized

Now the problem: When I need this variable in another class I can use one of two methods of getting it. Either by a getter [UserSettings getLongitude] or access the property [UserSettings strLongitude]

Then when I then trace out this string I sometimes get a badaccess error or random garbage. If I trace out the string as a float %F it works just fine.

Why is this happening? The string defaults back to the original data type of the variable.

Any he开发者_运维问答lp would be appreciated.


strLongitude might need to be retained.


It sounds like some code is accidentally calling the string setter with a float argument.


I realize that this isn't directly answering your question, but why store the co-ordinates in strings?

Why not store them as, well, floats? For example,

@interface UserSettings
{
    float longitude;
}

@property (nonatomic, assign) float longitude;

@end

Also, your UserSettings class sounds very similar to NSUserDefaults...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜