访问最终类的@NSManaged属性时出现Swift链接器错误 [英] Swift linker error when accessing @NSManaged properties of a final class
问题描述
我在一个较大的项目中遇到了问题,并将其归结为这个简单的代码.出于演示目的,我在Model.swift文件中创建了一个新的Swift项目,其中包含以下内容:
I'm having issues in a larger project, and boiled it down to this simple code. For demo purposes, I have created a new Swift project with the following in a Model.swift file:
import Foundation
import CoreData
class A: NSManagedObject {
@NSManaged var foo: String
}
final class B: A {
@NSManaged var bar: String
}
func testB(obj: B) -> String {
return "\(obj.foo) \(obj.bar)"
}
这可以编译,但是链接器抱怨访问 bar
:
This compiles, but the linker complains about accessing bar
:
Undefined symbols for architecture armv7:
"__TFC21TestFinalManagedClass1Bg3barSS", referenced from:
__TF21TestFinalManagedClass5testBFCS_1BSS in Model.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
@NSManaged var
在 final类
中的组合似乎是导致错误的原因.(包含了来自 A
的类继承关系,以证明 foo
属性可在类型为 B
的对象上访问,但不能访问bar
属性.)
The combination of an @NSManaged var
in a final class
seems to be what causes the error. (The class inheritance from A
is included to demonstrate that the foo
property is accessible on an object of type B
, but not the bar
property.)
我正在使用Xcode版本6.1(6A1052d).
I am using Xcode Version 6.1 (6A1052d).
文档中是否存在一些关于将 NSManagedObject
子类标记为最终规则的规则?还是这仅仅是编译器/链接器中的错误?
Is there some rule hidden in the documentation about marking an NSManagedObject
subclass as final? Or is this just a bug in the compiler/linker?
推荐答案
此问题已在Xcode 6.3 beta中得到解决.
This issue has been resolved in Xcode 6.3 beta.
这篇关于访问最终类的@NSManaged属性时出现Swift链接器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!