4

I tried out the following code in playground

import UIKit let label = UILabel() let textView = UITextView() let labelText = label.text // nil let textViewText = textView.text // "" 

If I Option click lableText, the type is String?.
If I Option click textViewText, the type is String!.

Why is the Label text an optional while the TextView text isn't?

4
  • In what exact version of Xcode? Commented Aug 9, 2015 at 23:46
  • I got the same results testing this in Xcode 6.4 and Xcode 7.0 beta. Commented Aug 9, 2015 at 23:48
  • 5
    Ultimately, the answer is that Apple hasn't finished updating all of their libraries to use Objective-C nullability annotations. Eventually, there should be no implicitly unwrapped optionals (!) left in the Apple libraries (by the time they're done). Commented Aug 9, 2015 at 23:49
  • Apparently this still stands as a legitimate question in 2023. @nhgrif if Apple was working on updating these values they would have done it already. Commented Feb 23, 2023 at 12:39

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.