- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
您好 Stacked 专家!
我的问题:如何从 CLLocationDegrees 值生成字符串?
失败的尝试:
1. NSLog(@"Value: %f", currentLocation.coordinate.latitude); //Tried with all NSLog specifiers.
2. NSNumber *tmp = [[NSNumber alloc] initWithDouble:currentLocation.coordinate.latitude];
3. NSString *tmp = [[NSString alloc] initWithFormat:@"%@", currentLocation.coordinate.latitude];
当我查看 CLLocationDegrees 的定义时,它清楚地表明这是一个 double 值:
typedef double CLLocationDegrees;
我在这里错过了什么?这让我发疯了......请帮我挽救一下!
提前致谢并致以最诚挚的问候。//放弃
最佳答案
这些是正确的:
NSLog(@"Value: %f", currentLocation.coordinate.latitude); //Tried with all NSLog specifiers.
NSNumber *tmp = [[NSNumber alloc] initWithDouble:currentLocation.coordinate.latitude];
这是错误的,因为 coordinate.latitude 不是 nsstring 可能期望的对象。
NSString *tmp = [[NSString alloc] initWithFormat:@"%@", currentLocation.coordinate.latitude];
如果你想要一个 NSString:
myString = [[NSNumber numberWithDouble:currentLocation.coordinate.latitude] stringValue];
或
NSString *tmp = [[NSString alloc] initWithFormat:@"%f", currentLocation.coordinate.latitude];
马可
关于iphone - 从 CLLocationDegrees 生成一个字符串,例如在 NSLog 或 StringWithFormat 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1329008/
这个问题在这里已经有了答案: How to add percent sign to NSString (7 个回答) 6年前关闭。 我搜索并找不到这个答案...... 如果我有这个,我怎样才能让它显示
我不知道我在这里错过了什么。我正在尝试使用 [NSString stringWithFormat] 函数连接字符串。这就是我正在做的事情。 NSString *category = [row obje
我有为 MD5 munge 准备消息的 java 代码 private static char[] jimsCopyRight = { 'C'、'o'、'p'、'y'、'r'、'i'、'g'、'h'、
我正在尝试使用 MFMailComposeViewController 撰写电子邮件,并且我正在使用绘制表格的 HTML 字符串。它有 265 个参数,所以我必须像这样传递它: [mailViewCo
我需要知道是否有一种方法可以使用 if 语句来显示某些 nsstring,具体取决于 NSString 是否包含任何数据。 我有一个名为 visitorInfo 的 nsstring。 该字符串使用来
调试如下代码时 NSString *var1 = @"blaa"; NSString *var2 = @"blaaaaa"; NSString* script = [NSString stringWi
我对StringWithFormat有疑问不工作。调试器表示返回的字符串不是 NSString (而且它不为空),因此我用假设的 NSString 进行调用将与方法选择器不匹配,并且我的应用程序崩溃。
简单/基本问题: 如果我不关心格式化所获取的日期,两者之间的性能差异是什么? NSDate *date = [NSDate date]; NSSting *dateString = [NSStri
我有一个枚举属性: typedef enum syncCodeTypes { kCodeNull, kCodeFoo, kCodeBar, kCodeDone } sy
此代码在名为username的UILabel中显示了用户的caption caption.text = [NSString stringWithFormat:@"@%@",[data objectFo
我知道方法stringWithFormat通常使用如下: [NSString stringWithFormat: @"%@ %@", arg1, arg2]; 我的问题是,这个方法的最后一个参数的类型
如果达到给定的有效位数,我想将 double 转换为字符串,并自动(!)从十进制切换到科学数(类似于 stringWithFormat(“.5g”)!)。示例: 55555 -> "55555" 55
我正在为我的应用程序提取推文,我希望能够以特定方式和颜色设置我的推文的格式。例如,这是一条简单的推文... "@somename This is a sample tweet from twitter
谁能解释为什么这段代码能完美运行: int thumbnailPrefix = trunc([newGraph.dateCreated timeIntervalSinceReferenceDate])
当我阅读如何在 iOS 中使用 Sqlite 时,我遇到了以下行 NSString *query = [NSString stringWithFormat:@"SELECT * FROM tableN
我正在将一些 Objective C(一种我从未使用过的语言......)移植到 C# 项目中,并进入了以下行: altStr = [NSString stringWithFormat:@"%.16f
如果这是一个菜鸟问题,我深表歉意。 我一直在关注this关于 mapkit 的教程,我无意中发现了这行代码 NSString *json = [NSString stringWithFormat:fo
我最近在使用 NSString 的 stringWithFormat: 方法时遇到了很多麻烦。我已经编写了一个对象,它允许您将 N 行文本(由新行分隔)居中、向右或向左对齐。我逻辑的核心是 NSStr
在我的 appDelegate 中,我正在使用 LocationManager : - (void)locationManager: (CLLocationManager *)manager
我将我的申请提交给苹果审核。苹果拒绝并给了我以下崩溃报告。 Thread 0 Crashed: 1 Foundation 0x3595dd04 _NSDe
我是一名优秀的程序员,十分优秀!