铸造失败可能与指针有关
Casting failed maybe related to Pointer
场景
场景包含 2 classes 操作和地点
这 2 个 class 如下所述相关
Operation{
storedAt : Date
type -> OperationType (Pointer)
place -> Places (Pointer)
}
Places {
title : String
type -> OperationType (Pointer)
location -> PFGeoPoint
}
我会做什么这只是检索用户附近的地方。为此,我使用了:
func getNearPlaces(location: CLLocation){
if location.isZero() {
return
}
var placeQuery = PFQuery(className: "Places")
println("getNearPlaces location \(location)")
placeQuery.whereKey("location", nearGeoPoint: PFGeoPoint(location:location), withinKilometers: 2)
placeQuery.whereKey("type", equalTo: detailItem.type)
placeQuery.limit = 15
placeQuery.findObjectsInBackgroundWithBlock { (objects:[AnyObject]?, error:NSError?) -> Void in
if error != nil {
println("error: \(error)")
return
}
println("results: \(objects?.count)")
if let objs = objects as? [PFObject] {
println("casting to [PFObject] ok")
}
if let objs = objects as? [Places] {
println("casting to [Places] ok")
self.places = objs
}
self.updateLocationOnMap()
}
}
其中 detailItem 是 Operations
的子class
现在是重点!如果 Operations class 有 NO 将所有行的指针列在 class 上赋值,一切正常。
results: Optional(3)
casting to [PFObject] ok
casting to [Places] ok
接下来我为 detailItem.place 分配了 [Places] 值之一,我继续使用应用程序。一切都好。
当我再次启动应用程序并且 detailItem.place 已稳定时,这是我的输出:
results: Optional(3)
casting to [PFObject] ok
投射到[地点]失败
有人能解释一下为什么吗?它与 di parse 或 swift 相关吗?我做错了什么吗?
我再补充一些细节:
根据 Parse.com 文档中的定义:
class Places:PFObject,PFSubclassing{
override class func initialize() {
struct Static {
static var onceToken : dispatch_once_t = 0;
}
dispatch_once(&Static.onceToken) {
self.registerSubclass()
}
}
static func parseClassName() -> String {
return "Places"
}
@NSManaged var title:String
@NSManaged var type:OperationsType
@NSManaged var location:PFGeoPoint
}
在从上述 PFQuery 检索到的对象的输出下方:
[<Places: 0x7fb94dc9e9d0, objectId: yFDNHinajo, localId: (null)>
{
location = "<PFGeoPoint: 0x7fb94d587ad0, latitude: 95.497511, longitude: 19.224867>";
title = tamoilled;
type = "<OperationsType: 0x7fb94844a2f0, objectId: 2IPOWNo1lM>";
},
<Places: 0x7fb94a84b2f0, objectId: zlh3CMVu0t, localId: (null)>
{
location = "<PFGeoPoint: 0x7fb94dc63f20, latitude: 95.498064, longitude: 19.226219>";
title = "new Place";
type = "<OperationsType: 0x7fb94844a2f0, objectId: 2IPOWNo1lM>";
},
<Places: 0x7fb94dc9f8f0, objectId: ymY7SlA3Is, localId: (null)>
{
location = "<PFGeoPoint: 0x7fb94dce4e70, latitude: 95.510635, longitude: 19.217392>";
title = "Agip 2";
type = "<OperationsType: 0x7fb94844a2f0, objectId: 2IPOWNo1lM>";
}]
解析iOS sdk 1.7.2, Xcode 6.3.1
关于 didFinishLaunchingWithOptions
ParseCrashReporting.enable();
Parse.enableLocalDatastore()
Parse.setApplicationId("...", clientKey:"...");
更新
我替换了
println("results: \(objects?.count)")
if let objs = objects as? [PFObject] {
println("casting to [PFObjects] ok \(objs)" )
}
和
self.places = []
for result in objects! {
println("object \(result)")
if let place = result as? Places {
println("place ok")
self.places.append(place)
}
}
结果是 detailItem.place 对应的 Places 对象没有强制转换为 Places 即使看起来是正确的! (注意第一个字典。它后面没有 'place ok')
object <Places: 0x7ff5a0f64be0, objectId: yFDNHinajo, localId: (null)> {
location = "<PFGeoPoint: 0x7ff5a312c720, latitude: 95.497511, longitude: 19.224867>";
title = tamoilled;
type = "<OperationsType: 0x7ff5a0edd520, objectId: 2IPOWNo1lM>";
}
object <Places: 0x7ff5a0fbcdc0, objectId: zlh3CMVu0t, localId: (null)> {
location = "<PFGeoPoint: 0x7ff5a3121f30, latitude: 95.498064, longitude: 19.226219>";
title = "new Place";
type = "<OperationsType: 0x7ff5a0edd520, objectId: 2IPOWNo1lM>";
}
place ok
object <Places: 0x7ff5a3724320, objectId: ymY7SlA3Is, localId: (null)> {
location = "<PFGeoPoint: 0x7ff5a31b8450, latitude: 95.510635, longitude: 19.217392>";
title = "Agip 2";
type = "<OperationsType: 0x7ff5a0edd520, objectId: 2IPOWNo1lM>";
}
place ok
更新 2
我试图在启动应用程序时执行相同的查询。没有错误,投射工作正常
我现在没有更多的资源。我认为这可能是来自 Parse.com 框架的错误。或者在我的场景中我不知道的东西(应该很简单)
已解决
随着新的 Parse 的更新,他们建议添加显式
Places.registerSubclass()
之前
Parse.setApplicationId()
场景
场景包含 2 classes 操作和地点
这 2 个 class 如下所述相关
Operation{
storedAt : Date
type -> OperationType (Pointer)
place -> Places (Pointer)
}
Places {
title : String
type -> OperationType (Pointer)
location -> PFGeoPoint
}
我会做什么这只是检索用户附近的地方。为此,我使用了:
func getNearPlaces(location: CLLocation){
if location.isZero() {
return
}
var placeQuery = PFQuery(className: "Places")
println("getNearPlaces location \(location)")
placeQuery.whereKey("location", nearGeoPoint: PFGeoPoint(location:location), withinKilometers: 2)
placeQuery.whereKey("type", equalTo: detailItem.type)
placeQuery.limit = 15
placeQuery.findObjectsInBackgroundWithBlock { (objects:[AnyObject]?, error:NSError?) -> Void in
if error != nil {
println("error: \(error)")
return
}
println("results: \(objects?.count)")
if let objs = objects as? [PFObject] {
println("casting to [PFObject] ok")
}
if let objs = objects as? [Places] {
println("casting to [Places] ok")
self.places = objs
}
self.updateLocationOnMap()
}
}
其中 detailItem 是 Operations
的子class现在是重点!如果 Operations class 有 NO 将所有行的指针列在 class 上赋值,一切正常。
results: Optional(3)
casting to [PFObject] ok
casting to [Places] ok
接下来我为 detailItem.place 分配了 [Places] 值之一,我继续使用应用程序。一切都好。
当我再次启动应用程序并且 detailItem.place 已稳定时,这是我的输出:
results: Optional(3)
casting to [PFObject] ok
投射到[地点]失败
有人能解释一下为什么吗?它与 di parse 或 swift 相关吗?我做错了什么吗?
我再补充一些细节:
根据 Parse.com 文档中的定义:
class Places:PFObject,PFSubclassing{
override class func initialize() {
struct Static {
static var onceToken : dispatch_once_t = 0;
}
dispatch_once(&Static.onceToken) {
self.registerSubclass()
}
}
static func parseClassName() -> String {
return "Places"
}
@NSManaged var title:String
@NSManaged var type:OperationsType
@NSManaged var location:PFGeoPoint
}
在从上述 PFQuery 检索到的对象的输出下方:
[<Places: 0x7fb94dc9e9d0, objectId: yFDNHinajo, localId: (null)>
{
location = "<PFGeoPoint: 0x7fb94d587ad0, latitude: 95.497511, longitude: 19.224867>";
title = tamoilled;
type = "<OperationsType: 0x7fb94844a2f0, objectId: 2IPOWNo1lM>";
},
<Places: 0x7fb94a84b2f0, objectId: zlh3CMVu0t, localId: (null)>
{
location = "<PFGeoPoint: 0x7fb94dc63f20, latitude: 95.498064, longitude: 19.226219>";
title = "new Place";
type = "<OperationsType: 0x7fb94844a2f0, objectId: 2IPOWNo1lM>";
},
<Places: 0x7fb94dc9f8f0, objectId: ymY7SlA3Is, localId: (null)>
{
location = "<PFGeoPoint: 0x7fb94dce4e70, latitude: 95.510635, longitude: 19.217392>";
title = "Agip 2";
type = "<OperationsType: 0x7fb94844a2f0, objectId: 2IPOWNo1lM>";
}]
解析iOS sdk 1.7.2, Xcode 6.3.1
关于 didFinishLaunchingWithOptions
ParseCrashReporting.enable();
Parse.enableLocalDatastore()
Parse.setApplicationId("...", clientKey:"...");
更新
我替换了
println("results: \(objects?.count)")
if let objs = objects as? [PFObject] {
println("casting to [PFObjects] ok \(objs)" )
}
和
self.places = []
for result in objects! {
println("object \(result)")
if let place = result as? Places {
println("place ok")
self.places.append(place)
}
}
结果是 detailItem.place 对应的 Places 对象没有强制转换为 Places 即使看起来是正确的! (注意第一个字典。它后面没有 'place ok')
object <Places: 0x7ff5a0f64be0, objectId: yFDNHinajo, localId: (null)> {
location = "<PFGeoPoint: 0x7ff5a312c720, latitude: 95.497511, longitude: 19.224867>";
title = tamoilled;
type = "<OperationsType: 0x7ff5a0edd520, objectId: 2IPOWNo1lM>";
}
object <Places: 0x7ff5a0fbcdc0, objectId: zlh3CMVu0t, localId: (null)> {
location = "<PFGeoPoint: 0x7ff5a3121f30, latitude: 95.498064, longitude: 19.226219>";
title = "new Place";
type = "<OperationsType: 0x7ff5a0edd520, objectId: 2IPOWNo1lM>";
}
place ok
object <Places: 0x7ff5a3724320, objectId: ymY7SlA3Is, localId: (null)> {
location = "<PFGeoPoint: 0x7ff5a31b8450, latitude: 95.510635, longitude: 19.217392>";
title = "Agip 2";
type = "<OperationsType: 0x7ff5a0edd520, objectId: 2IPOWNo1lM>";
}
place ok
更新 2
我试图在启动应用程序时执行相同的查询。没有错误,投射工作正常 我现在没有更多的资源。我认为这可能是来自 Parse.com 框架的错误。或者在我的场景中我不知道的东西(应该很简单)
已解决
随着新的 Parse 的更新,他们建议添加显式
Places.registerSubclass()
之前
Parse.setApplicationId()