我正在尝试编译一些快速代码
import Foundation
let BaseSocketErrorDomain = "com.thing.base_socket";
@objc internal protocol GATToIPBaseSocketDelegate {
@objc optional func txReady(_: GATToIPBaseSocket)
@objc optional func rxData(_: GATToIPBaseSocket, data:Data) -> Bool
@objc optional func didConnect(_: GATToIPBaseSocket)
@objc optional func didDisconnect(_: GATToIPBaseSocket, error: Error?)
}
@objc internal class GATToIPBaseSocket: NSObject {
enum SocketError: Error {
case notConnected
case noSpaceAvailable
case sendError
}
weak var delegate: GATToIPBaseSocketDelegate?
private(set) var isConnected: Bool = false
func openConnection() {
// nothing yet
}
}
导致以下错误
/home/pi/ReWork/GATToIP/GATToIP/BaseSocket.swift:20:2: error: only classes that inherit from NSObject can be declared @objc
@objc internal class GATToIPBaseSocket: NSObject {
~^~~~~
但是,该类非常明显地标记为@objc
并且继承自NSObject
。谁能告诉我我在这里缺少什么?