Swift: Comparing Implicitly Unwrapped Optionals results in "unexpectedly found nil while unwrapping an Optional values" <p>If got this class and would like to compare instances of it based on the value </p> <pre><code>class LocationOption: NSObject { var name:String! var radius:Int! var value:String! override func isEqual(object: AnyObject?) -&gt; Bool { if let otherOption = object as? LocationOption { return (self.name == otherOption.name) &amp;&amp; (self.radius == otherOption.radius) &amp;&amp; (self.value == otherOption.value) } return false } } </code></pre> <p>When executing this: </p> <pre><code>var a = LocationOption() var b = LocationOption() a.name = "test" b.name = "test" if a == b { // Crashes here!! print("a and b are the same"); } </code></pre> <p>This crashes with "unexpectedly found nil while unwrapping an Optional value"? You can copy all this into a Playground to reproduce.</p> <p>It seems to be due to the <code>Implicitly Unwrapped Optionals</code>. If I declare all fields as Optionals it works as expected.</p> <p>But in my case, I would like to have these properties as <code>Implicitly Unwrapped Optionals</code>. How should I write the isEqual?</p> <p>===</p> <p>UPDATE: @matt is right and as I didn't want to change to "regular" Optionals I ended up with this:</p> <pre><code>class LocationOption: Equatable { var name:String! var requireGps:Bool! var radius:Int! var value:String! } func ==(lhs: LocationOption, rhs: LocationOption) -&gt; Bool { let ln:String? = lhs.name as String?, rn = rhs.name as String? let lr = lhs.radius as Int?, rr = rhs.radius as Int? return ln == rn &amp;&amp; lr == rr } </code></pre>