ios8 - Issues with Binary expression in swift -
ios8 - Issues with Binary expression in swift -
i want know difference between equal(==) , identical(===) expressions. why using pattern match (~=) expression. can utilize these expressions. can explain please. in advance.
my sample code is:
var sample1 = "steve jobs" var sample2 = "steve jobs" sample1 === sample2 ? println("its equal"):println("not equal") //result "not equal" var sample3 = "steve jobs" var sample4 = "steve jobs" sample3 == sample4 ? println("its equal"):println("not equal")//result "its equal" the utilize of other binary expressions examples welcome. think pattern match not exist in objective c.
the illustration have written cannot compiled
and that's because === defined object types swift string value type.
in general, means 2 object intances same instance. while == checks equality of contents.
you can utilize === nsstring instances object types:
var sample1: nsstring = "string1" var sample2: nsstring = "string1" sample1 === sample2 //false the pattern matching look ~= used switch - case command statement. switch(value) defines value , every case pattern: defines pattern match. ~= function called every case decide if case statements should executed or no.
swift ios8 xcode6
Comments
Post a Comment