swift_dynamicCastClassSwift中的无条件问题 [英] swift_dynamicCastClassUnconditional issues in swift
问题描述
我迅速拥有以下NSManagedObject
:
import Foundation
import CoreData
public class User: NSManagedObject {
@NSManaged public var first_name: String
@NSManaged public var last_name: String
}
我有一个提供以下功能的类:
I have a class which provides the value with a function below:
- (id)getUserAtIndexPath:(NSIndexPath *)indexPath {
User *user = [self.fetchedResultsController objectAtIndexPath:indexPath];
return user;
}
当我从Objective-C
类调用此函数时,一切正常.我这样叫:
When I call this function from an Objective-C
class, everything works fine. I call like so:
User *user = [self.userAccessor getUserAtIndexPath:indexPath];
我可以从那里继续.当我像这样从Swift
类调用它时:
And i'm able to continue from there. When I call it from a Swift
class like so:
let user: User = self.userAccessor.getUserAtIndexPath(indexPath) as User
我每次都得到swift_dynamicCastClassUnconditional
.我做错了什么吗?为什么同一功能在Objective-C
中起作用,而不在Swift
中起作用?我什至设置了一个断点,并可以在Swift
调用上确认返回值是有效变量! Swift
只是缺少它的一些原因.
I get the swift_dynamicCastClassUnconditional
every time. Is there anything i'm doing wrong? Why is the same function working in Objective-C
and not Swift
? I even put a break point and can confirm on the Swift
call the return is a valid variable! Some how Swift
is just missing it.
我尝试阅读以下内容:
由NSFetchRequest返回的AnyObject数组,错误与快速动态投放失败";在XCTestCase中投放到Swift XCode 6 Beta 4中
还有什么我想念的吗?
推荐答案
我在这里找到了解决方案:
I got the solution here:
基本上,我不得不将@objc(User)
放在受管理对象代码的正上方.因此,如下所示:
Basically I had to put @objc(User)
right above managed object code. So as per below:
@objc(User)
public class User: NSManagedObject {
@NSManaged public var first_name: String
@NSManaged public var last_name: String
}
这解决了问题.结案了.
This solved the problem. Case closed.
这篇关于swift_dynamicCastClassSwift中的无条件问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!