so i am trying to define a swift class that will work in both swift and objective-c.
所以我试图定义一个快速和客观的快速课程。
When i try this way
当我尝试这种方式
import Foundation
@objc class TestClass
{
private var m_FirstName : String
private var m_LastName : String
private var m_Id : String
init()
{
m_FirstName = ""
m_LastName = ""
m_Id = "userIdNotSet-badescuga"
}
init(firstName:String, lastName:String, id:String)
{
m_FirstName = firstName
m_LastName = lastName
m_Id = id
}
}
i get a weird error:
我得到一个奇怪的错误:
Command failed due to signal: Segmentation fault: 11
由于信号命令失败:分段故障:11
which is somewhat understandable because i don't have a String
class in objective-c. But even if i change all the String
class objects to NSString
i still get the same error.
这有点可以理解,因为我在objective-c中没有String类。但即使我将所有String类对象更改为NSString,我仍然会得到相同的错误。
What am i doing wrong?? I using Xcode 6.1.1 and i've also tried it on xcode 6.2.3 Beta
我究竟做错了什么??我使用Xcode 6.1.1,我也尝试过xcode 6.2.3 Beta
UPDATE
UPDATE
I also tried inheriting from the NSObject class with the same result: i get the same error
我也尝试从NSObject类继承具有相同的结果:我得到相同的错误
UPDATE 2
更新2
I get the error when i'm trying to compile the project. I am not using this class in any way. It is just for test purposes.
我在尝试编译项目时遇到错误。我没有以任何方式使用这个类。它仅用于测试目的。
1 个解决方案
#1
0
This is probably due to your stored properties being marked with private access. Swift compiler doesn't add @objc automatically to those marked as private (since it's assumed internal use).
这可能是由于您的存储属性标记为私有访问。 Swift编译器不会自动将@objc添加到标记为私有的那些(因为它假定为内部使用)。
Try prepending @objc before each private properties and see how it goes.
尝试在每个私有属性之前预先添加@objc,看看它是如何进行的。
Also if a class inherits NSObject there's no need for explicit @objc tag.
此外,如果一个类继承了NSObject,则不需要显式的@objc标记。
#1
0
This is probably due to your stored properties being marked with private access. Swift compiler doesn't add @objc automatically to those marked as private (since it's assumed internal use).
这可能是由于您的存储属性标记为私有访问。 Swift编译器不会自动将@objc添加到标记为私有的那些(因为它假定为内部使用)。
Try prepending @objc before each private properties and see how it goes.
尝试在每个私有属性之前预先添加@objc,看看它是如何进行的。
Also if a class inherits NSObject there's no need for explicit @objc tag.
此外,如果一个类继承了NSObject,则不需要显式的@objc标记。