Why is the extension of my Swift class not visible outside the defining file?

可紊 提交于 2019-11-30 21:42:39

问题


I have an Xcode-generated NSManagedObject class for my CoreData model.

@objc(SomeClass) class SomeClass : NSManagedObject { /* ... */ }

It is defined in a file named 'SomeClass.swift'. I would like to extend this class, so I created 'SomeClassExtension.swift'. I define the extension like this:

extension SomeClass {
    class func typeMethod1() {}
    func instanceMethod2() {}
}

These extension methods can be used within this defining file, but they are not visible outside of it. What is causing this issue?


回答1:


It sounds like your new file (SomeClassExtension.swift) didn't get included in the correct target. Double-check the file's target membership by selecting the file in Xcode, then opening the "File Inspector" (View menu > Utilities > Show File Inspector). Make sure the correct targets are checked under the Target Membership heading.




回答2:


I don't see any public modifiers on those methods.



来源:https://stackoverflow.com/questions/26111440/why-is-the-extension-of-my-swift-class-not-visible-outside-the-defining-file

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