我想在我的添加,添加顏色選擇器我用這個https://github.com/gizmosachin/ColorSlider庫,只寫在迅速和我使用的Objective-C。我已經遵循本指南How to call Objective-C code from Swift瞭解如何在Objective-C項目中添加swift庫。我99%確定我已經正確配置了xcode,因爲我可以導入swift庫並運行我的應用程序而不出錯,只有當我嘗試實例化應用程序崩潰的swift類時,我發現init方法swift類被無限調用。該庫的源代碼是一個文件,以防萬一參考上市(https://github.com/gizmosachin/ColorSlider/blob/master/Source/ColorSlider.swift)初始化的目標C項目迅速類導致無限循環
這裏的初始化方法之一(另inits是覆蓋)
// MARK: Initializers
convenience init() {
println("hi there swift")
self.init()
backgroundColor = UIColor.clearColor()
}
在我的日誌我看到「你好,很快「打印了很多次。這是我開始迅速類
ColorSlider *colorSlider = [[ColorSlider alloc] init];
我知道,包含上述的代碼行的功能,因爲我使用的NSLog(@「產出」),看看有多少次這樣的顯示出來,並且只被調用一次輸出看起來像這樣
output
hi there swift
hi there swift
hi there swift
hi there swift
hi there swift
etc...to infinity or until app crashes
我正在實例化Swift類嗎?我不知道爲什麼SWIFT類的init方法被稱爲無限
---- UPDATE -----
嘗試刪除self.init()或使用init(幀替換:的CGRect)或init (編碼器aDecoder:NSCoder) – anhtu