“und in Swift6” Code-Antworten

und in Swift6

// A logical and in swift is "&&"
// A logical or in swift is "||"

//E.g.
if a > 0 && i == j || f < 3 {
    ...
}
Fancy Flatworm

=== Swift

//Triple Equals check that both object's reference is same or not.

class TripleEqualsExample : Equatable {
    let value: Int
     

    init(value: Int) {
        self.value = value
    }

    static func == (lhs: TripleEqualsExample, rhs: TripleEqualsExample) -> Bool {
        return lhs.value == rhs.value
    }
}



let instances1 = TripleEqualsExample(value: 5)
let instances2 = TripleEqualsExample(value: 5)

let instances3 = instances1

if instances1 == instances2 {
  print("the two instances are equal!")
}


if instances1 === instances2 {
  //It does not enter here
} else {
  print("the two instances are not identical!")
}


if instances3 === instances1 {
  print("the two instances are identical!")
}
Developer101

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen