[英]iOS Swift: init not being fired?
I have a simple class: 我有一堂简单的课:
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)
}
}
}
(Don't mind the btDiscoverySharedInstance, that's another class) (不要介意btDiscoverySharedInstance,那是另一个类)
When I call var foo = BTManager()
I do not see "Init BTManager" in the console. 当我调用var foo = BTManager()
,在控制台中看不到“ Init BTManager”。 Why is that? 这是为什么? I have no idea why this wouldn't work... 我不知道为什么这行不通...
我从结构调用初始化器-显然swift不喜欢那样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.