我有一个简单的课程:
import UIKit
class BTManager: NSObject{
var allowTX = false
override init(){
super.init()
print("Init BTManager")
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("connectionChanged:"), name: BLEServiceChangedStatusNotification, object: nil)
btDiscoverySharedInstance
}
func connectionChanged(notification: NSNotification) {
// Connection status changed. Indicate on GUI.
let userInfo = notification.userInfo as! [String: Bool]
dispatch_async(dispatch_get_main_queue(), {
// Set image based on connection status
if let isConnected: Bool = userInfo["isConnected"] {
if isConnected {
self.allowTX = true
variables.connected = true
} else {
self.allowTX = false
variables.connected = false
}
}
});
}
func sendSerial(serial: String) {
// 1
if !allowTX {
return
}
if let bleService = btDiscoverySharedInstance.bleService {
bleService.sendSerial(serial)
}
}
}
(不要介意btDiscoverySharedInstance,这是另一个班级)
当我致电var foo = BTManager()
时,我没有看到" Init BTManager"在控制台中。这是为什么?我不知道为什么这不起作用......
答案 0 :(得分:0)
我是从一个结构中调用我的初始化程序 - 显然很快就不喜欢它。