xcode 使用未声明的类型“对象”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31477613/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Use of undeclared type 'Object'
提问by Alex
This is so weird. Normally I could understand a class not being declared, but this is claiming the Object class itself is not declared. NSObject works, but the way my project is setup I need it to be a pure Swift Object. My class header looks like this:
这太奇怪了。通常我可以理解一个没有被声明的类,但这是声称 Object 类本身没有被声明。NSObject 有效,但我的项目设置方式我需要它是一个纯 Swift 对象。我的类标题如下所示:
import UIKit
import Foundation
class Person: Object {
I know foundation isn't really necessary, I just added it because I wasn't sure if that was causing me issues. The issue is occurring in both actual projects and playgrounds as well as in Xcode 6 and the latest Xcode 7 beta with Swift 2.0
我知道基础并不是真正必要的,我只是添加了它,因为我不确定这是否会导致我出现问题。该问题在实际项目和 Playgrounds 以及 Xcode 6 和最新的 Xcode 7 beta 和 Swift 2.0 中都发生
回答by Khawar Islam
if you are using Realm then import
如果您使用的是 Realm 然后导入
import RealmSwift
Complete syntax of class.
类的完整语法。
import UIKit
import RealmSwift
class User: Object {
}
If you face any difficulty to implement this code. Watch below video Link: https://youtu.be/5Z8tBKwk6-c
如果您在实现此代码时遇到任何困难。观看以下视频链接:https: //youtu.be/5Z8tBKwk6-c
回答by vadian
Just remove : Object
. Pure Swift classes don't need to inherit from a superclass
只需删除: Object
. 纯 Swift 类不需要从超类继承
回答by Bart?omiej Semańczyk
Pure Swift object doesn't inherit from a superclass:
纯 Swift 对象不继承自超类:
class Person {}
class Person {}
You can read Classes and Structures
您可以阅读类和结构