1

I was learning Swift and developing my test project on first XCode Beta, but few days ago I've downloaded XCode Beta4 and that's showed error in build.

My code:

class LoginModalViewController: UIViewController {

  @IBOutlet var usernameField : UITextField
  @IBOutlet var passwordField : UITextField
  @IBOutlet var loginButton : UIButton

  ...

Previously that's how I defined outlets inside controller, but in new beta it gives me an error IBOutlet property has non-optional type UITextField and suggests me to fix it in 2 ways:

  • add ! after each var
  • add ? after each var

I know that ? means optional and if I'll choose it then I need to update my code like usernameField.becomeFirstResponder() into usernameField!.becomeFirstResponder()

Adding ! solves errors perfectly..

So as I understand there are only these two ways to create properties inside class, am I right?

It will be handy to find the changelog of such Swift syntax language updates.

Kosmetika
  • 20,774
  • 37
  • 108
  • 172
  • 2
    Read the Beta5 release documents. "The UIView, NSView, UIFont, and UIApplicationDelegate classes have been audited for optional conformance, removing most implicitly unwrapped optionals from their interfaces. This clarifies the nullability of their properties and arguments / return values of their methods. The changes in Beta 5 are simply the first step; more refinements to the SDK will come in future betas. (17892713)!" I suspect that included their subclasses as well. – zaph Aug 06 '14 at 15:28
  • @Zaph could you take a look on this one - http://stackoverflow.com/questions/25164313/swift-must-call-a-designated-initializer-of-the-superclass-skspritenode-error ? Also broken with new beta.. – Kosmetika Aug 06 '14 at 15:35
  • I don't write code in Swift and have no intention to. I am learning the language and do read the Release Notes. – zaph Aug 06 '14 at 15:40

1 Answers1

5

Actually, something like var usernameField : UITextField is a perfectly valid property declaration in Swift, even though it isn't declared as an optional. In your version of Swift, the issue you were having is that properties annotated with @IBOutlet must be optionals.

Changes to the Swift language may be found in the Xcode 6 beta release notes, here.

On a side note, since you mentioned you'd updated to Xcode Beta 4, I'd like to point out that at the time of writing, Xcode Beta 5 was just released 2 days ago :)

Kamaros
  • 4,536
  • 1
  • 24
  • 39