【发布时间】:2019-04-30 16:27:53
【问题描述】:
我有这段代码:
import Foundation
import CoreBluetooth
public class Service {
static var centralManager: CBCentralManager!
private init() {}
public static func doSomething() {
centralManager = CBCentralManager(delegate: self, queue: nil)
}
}
但是在构建时,它说我的 doSomthing() 函数的一行中有错误 Type of expression is ambiguous without more context。这可能是什么原因,我怎样才能让这个小类构建和运行?
【问题讨论】:
-
您在类方法中没有
self。我想这是主要问题。您可能对单例模式(在 Swift 中通常命名为 sharedInstance/shared)感兴趣。 -
那么我应该创建另一个类作为 CBCentralManager 的委托类吗?
标签: swift class core-bluetooth ambiguous