iluvcapra iluvcapra - 2 years ago 80
Swift Question

NSPlaceholders and Swift

I'm looking at the

of an Array Controller and I want to know when the selection is multiple values or none. In ObjC we'd do this by getting the selection as an
and checking it's raw equality with the various placeholder markers:
, and

But this doesn't work in Swift:

let currentValue = eventsArrayController.selection.valueForKey("enabled")

if let markerVal = currentValue {
if markerVal == NSMultipleValuesMarker {
// this doesn't compile, AnyObject's can't be compared with ==
switch markerVal {
case NSNoValueMarker:
// this doesn't compile, an AnyObject is not a valid pattern

How do I test the value of placeholder markers in Swift?

Answer Source

In Swift, == is meant to check for value equality (that is, if two objects contain the same data, regardless of whether they share the same memory location or not). Use the === operator to check for reference equality (which tests if two objects share the same memory location).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download