为什么在定义文件之外看不到我的Swift类的扩展名? [英] Why is the extension of my Swift class not visible outside the defining file?

查看:107
本文介绍了为什么在定义文件之外看不到我的Swift类的扩展名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的CoreData模型有一个Xcode生成的NSManagedObject类.

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

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

它在名为"SomeClass.swift"的文件中定义.我想扩展此类,所以我创建了"SomeClassExtension.swift".我这样定义扩展名:

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?

推荐答案

听起来您的新文件(SomeClassExtension.swift)没有包含在正确的目标中.通过在Xcode中选择文件,然后打开文件检查器"(查看"菜单>实用程序">显示文件检查器"),仔细检查文件的目标成员资格.确保在目标成员身份标题下检查了正确的目标.

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.

这篇关于为什么在定义文件之外看不到我的Swift类的扩展名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆