Swift linker error when accessing @NSManaged properties of a final class

心已入冬 提交于 2019-12-11 03:16:27

问题


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)"
}

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)

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.)

I am using Xcode Version 6.1 (6A1052d).

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?


回答1:


This issue has been resolved in Xcode 6.3 beta.



来源:https://stackoverflow.com/questions/26616893/swift-linker-error-when-accessing-nsmanaged-properties-of-a-final-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!