iOS Swift:init没有被解雇?

时间:2015-08-20 18:03:18

标签: ios swift initialization

我有一个简单的课程:

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"在控制台中。这是为什么?我不知道为什么这不起作用......

1 个答案:

答案 0 :(得分:0)

我是从一个结构中调用我的初始化程序 - 显然很快就不喜欢它。