2016-04-27 21 views
0

我做了一個數組:陣副本顯示0 1,而不是真正的假斯威夫特

var hugett = [[[true, false], [true, true], [true, true, true], [true, true, false, false], [false]],[]] 

以及陣列中取得的第一個索引的副本:

tempott = hugett[0] 

BUT!當我打印我得到不同的結果,當我打印原始數組(hugett):

[[true, false], [true, true], [true, true, true], [true, true, false, false], [false]] 

當我打印副本(tempott),這是我得到:

((
     (
     1, 
     0 
    ), 
     (
     1, 
     1 
    ), 
     (
     1, 
     1, 
     1 
    ), 
     (
     1, 
     1, 
     0, 
     0 
    ), 
     (
     0 
    ) 
)) 

相反向我展示真假 - 我的錯誤是0/1?

回答

0

您可能正在使用NSLog("%@", tempott)來打印數組,這就是爲什麼它被橋接到Objective-C,而你得到這個而不是「真」和「假」。

只需用Swift的print打印它,您就會看到Bool值:print(tempott)

還有dump(tempott)可用於檢查對象。您的評論後

更新:

enter image description here

enter image description here

+0

我用印刷品打印: print(tempott)。 但問題不在於打印,問題是我需要使用tempott與true和false,因爲0/1我不能。 – Eliko

+0

'我用print打印:print(tempott)'對不起,但用'print'打印時我得到的是true和false,而不是0和1.我不能在Playground中重現你的問題。你必須對某件事感到困惑,請檢查你的代碼。 – Moritz

+0

你是怎麼創建你的tempott的? – Eliko

0

我創建數組爲:

var tempott: NSArray 

代替:

var tempott = [Array<Bool>]()