1

I have an Objective C class SomeClass which has a nullable property:

@property (nonatomic, strong) __nullable ClassA* clsAProperty;

In a Swift 1.2 (Xcode 6.3 beta 3) file, I attempt to assign the property to a nullable property:

private var clsAProperty : ClassA?
...
self.clsAProperty = SomeClass.someInstance().clsAProperty as ClassA?

This code is crashing with the following message:

Fatal Error: unexpectedly found nil while unwrapping an Optional value

Everything works as expected when compiled under Xcode 6.2.

Is this a bug, or am I missing anything? What optional is the runtime attempting to unwrap, when both are supposed to optional?

Léo Natan
  • 56,823
  • 9
  • 150
  • 195
  • There has been some change with respect to Objective-C and Nullability in XCode 6.3, check this link - https://developer.apple.com/swift/blog/?id=25 – rshankar Mar 18 '15 at 17:04
  • @rshankar I see nothing there to suggest a change in this regard from previous Swift iterations. – Léo Natan Mar 18 '15 at 17:15
  • Is it possible that `SomeClass.someInstance()` is `nil` or is that just placeholder code? – sbooth Mar 18 '15 at 17:57
  • @sbooth It's a placeholder code, and the instance is not nil. `clsAProperty` is, but that's acceptable. – Léo Natan Mar 18 '15 at 20:00

1 Answers1

0

Looks like it was an Xcode bug. Later betas fixed the issue.

Léo Natan
  • 56,823
  • 9
  • 150
  • 195