Swift: why is label.text optional but textView.text is an expanded string?

I tried the following code in a playground

import UIKit

let label = UILabel()
let textView = UITextView()

let labelText = label.text           // nil
let textViewText = textView.text     // ""

      

If I press Option lableText

, type String?

.
If I press Option textViewText

, type String!

.

Why is the label text optional if the TextView text is not?

+3
ios uilabel swift uitextview optional


source to share


No one has answered this question yet

See similar questions:

nine
How do I create class methods that conform to the protocol shared between Swift and Objective-C?

or similar:

641
Split string into array in Swift?
476
Why create "Implicitly Unwrapped Optionals" as it means you know what the value is?
385
What does "fatal error: unexpectedly found zero while unwrapping an optional value" mean?
243
What is an optional value in Swift?
129
What is "expanded value" in Swift?
nine
Why does UITextView concatenate attributes from the previously set Text attribute?
2
Swift - cast null base data string as optional value
0
Table list key Option - quick
0
Why is the default type of shortcut forced expanding optional?
-1
Swift 3 optional string for int



All Articles
Loading...
X
Show
Funny
Dev
Pics