变量不是 CFStringRef
我有这样的:
partenaire_lat = 48.8160525;
partenaire_lng = 2.3257800;
并获得这样的 NSString:
NSString *endPoint =[NSString stringWithFormat:@"%@,%@", partenaire_lat, partenaire_lng];
在某些上下文中使用这个 NSString 后,我得到这个愚蠢的错误:
Variable is not a CFString.
但如果我像这样创建 NSString:
endPoint = @"48.8160525,2.3257800"
它然后就完美了!
对于这个错误 Variable is not a CFString
我尝试了以下操作:
NSString *endPoint1 =[NSString stringWithFormat:@"%@,%@", partenaire_lat, partenaire_lng];
CFStringRef endPoint =(CFStringRef)endPoint1;
并尝试使用 endPoint
但这种方式都不起作用。有人有什么神奇的想法吗?谢谢
EDIT:partenaire_lat and partenaire_lng are both NSString!!
I have this:
partenaire_lat = 48.8160525;
partenaire_lng = 2.3257800;
And obtain a NSString 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!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您
一直说这两个变量是 NSString ,但您没有为它们分配 NSString 。您需要将
NSString
对象分配给NSString
变量 - 它们不会自动为您创建。因此,告诉您使用格式化字符串的答案是正确的。你真的应该这样做:
You have
You keep saying that the two variables are
NSString
s but you aren't assigningNSString
s to them. You need to assignNSString
objects toNSString
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:
纬度和经度是什么?我假设 float 或 double ..所以您应该使用
[NSString stringWithFormat:@"%f,%f", lat, lng];
(或者您希望格式化浮点数)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)您的代码有几个潜在的问题:
%@ 格式说明符需要对象参数,而看起来您传递的是普通浮点数(我在这里可能是错的,因为没有足够的上下文来确定)。如果确实如此,请将格式更改为 %f 以解决您的问题:
您的 endPoint1 字符串是自动释放的,如果您不保留它,它可能会在当前范围之外变得无效。因此,如果您尝试在其他方法中使用您的变量,您可能应该保留它。
You code has several potential problems:
%@ 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:
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
and do whatever you want to do with these two string :)