我正在进行潜水应用程序,其中一项功能是将潜水等级存储为CoreData中的两倍。界面应该能够从coredata对象中检索double值,然后在屏幕上显示。但是,我从代码中得到的问题是从对象返回的double非常小(e的功率为-315)。我不知道为什么会这样。
if let dives = self.diveSite?.logged_dives {
for dive in dives {
print("######### dive site info ########")
rating = Double(dive.rating) + rating
print(dive)
print("raw dive site rating is \(dive.rating)")
print("dive rating is \(rating)")
}
} else {
print("no logged_dives")
}
这是在控制台上打印出来的内容......
######### dive site info ########
<ScubaDoo.DiveLog: 0x7fe9ea02cbc0> (entity: DiveLog; id: 0xd000000000180002 <x-coredata://2B6F1E6F-1EDA-4910-91FA-0593E05F9EB2/DiveLog/p6> ; data: {
current = nil;
depth = 0;
"dive_at" = "0xd000000000140000 <x-coredata://2B6F1E6F-1EDA-4910-91FA-0593E05F9EB2/DiveSite/p5>";
id = nil;
latitude = 0;
longitude = 0;
rating = 5;
"sea_condition" = nil;
temperature = 0;
time = nil;
weather = nil;
})
raw dive site rating is 5.35679601527854e-315
dive rating is 1.06203402623994e-314
dive site rating is 1.06203402623994e-314
swift中的DiveLog对象如下所示。我真的对此没有任何线索。在获得评级属性时似乎有些东西是不受约束的?
import Foundation
import CoreData
extension DiveLog {
@NSManaged var time: NSDate?
@NSManaged var latitude: NSNumber?
@NSManaged var id: String?
@NSManaged var rating: NSNumber?
@NSManaged var depth: NSNumber?
@NSManaged var temperature: NSNumber?
@NSManaged var weather: String?
@NSManaged var current: String?
@NSManaged var sea_condition: String?
@NSManaged var longitude: NSNumber?
@NSManaged var dive_at: DiveSite?
}
答案 0 :(得分:1)
不确定刚刚发生了什么,但我升级到了XCode 7.3,并且问题得到解决。我猜这个问题出在IDE本身?