开发者

variable is not a CFStringRef

I have this:

partenaire_lat = 48.8160525; 
partenaire_lng = 2.3257800;

And obtain a NSStr开发者_StackOverflow中文版ing like this:

NSString *endPoint =[NSString stringWithFormat:@"%@,%@", partenaire_lat, partenaire_lng];

and after using this NSString in some context I get this stupid error:

Variable is not a CFString.

But if I create the NSString like this:

endPoint = @"48.8160525,2.3257800" it then works perfect!

For this error Variable is not a CFString I tried the following:

NSString *endPoint1 =[NSString stringWithFormat:@"%@,%@", partenaire_lat, partenaire_lng];
CFStringRef endPoint =(CFStringRef)endPoint1;

and tried to use endPoint but not working neither this way.Anyone any miraculous idea?Thx

EDIT:partenaire_lat and partenaire_lng are both NSString!!


You have

partenaire_lat = 48.8160525; 
partenaire_lng = 2.3257800;

You keep saying that the two variables are NSStrings but you aren't assigning NSStrings to them. You need to assign NSString objects to NSString variables - they aren't created for you automatically.

So the answers which are telling you to use formatted strings are correct. You really should be doing it like this:

partenaire_lat = [[NSString stringWithFormat:@"%f", 48.8160525] retain]; 
partenaire_lng = [[NSString stringWithFormat:@"%f", 2.3257800] retain];


what are lat and lng? i'm assuming float or double..so you should use [NSString stringWithFormat:@"%f,%f", lat, lng]; (or however you want the floats to be formatted)


You code has several potential problems:

  1. %@ format specifier expects object parameter, while it looks like you pass plain float (I may be wrong here as there's not enough context to be sure). Change format to %f to fix your problem if that's really the case:

    NSString *endPoint1 =[NSString stringWithFormat:@"%f,%f", partenaire_lat, partenaire_lng];
    
  2. Your endPoint1 string is autoreleased and may become invalid outside of current scope if you don't retain it. So if you try to use your variable in another method you probably should retain it.


All you need to do

NSString *latStr=[[NSNumber numberWithFloat:partenaire_lat] stringValue];
NSString *lngStr=[[NSNumber numberWithFloat:partenaire_lng] stringValue];

and do whatever you want to do with these two string :)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜