Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Identity operators in Swift

Tags:

swift

If a is identical to c, b is identical to c, why a is not identical to b?

var a = [1, 2, 3]
var b = a
var c = a[0...2]
a === c                    // true
b === c                    // true
a === b                    // false

If a, b, c are constants:

let a = [1, 2, 3]
let b = a
let c = a[0...2]
a === c                    // true
b === c                    // true
a === b                    // true
like image 247
Tao Avatar asked Oct 31 '22 22:10

Tao


1 Answers

You can remove the import Cocoa or import UIKit if you are playing with PlayGround to make it correct. It seems there is some type map thing in the Cocoa framework to mess things up. It should be a bug, I think.

like image 146
onevcat Avatar answered Nov 18 '22 02:11

onevcat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!