2016-04-27 20 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>]()