I'm working my way through the Swift table demos, and all of them seem have this same error message under 6.0.1. Not sure how to tackle this:
相关问题
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
- SwiftUI: UIImage (QRCode) does not load after call
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- Using if let syntax in switch statement
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Enum with associated value conforming to CaseItera
- Swift - hide pickerView after value selected
- Is there a Github markdown language identifier for
If you look up the
textLabel
property documentation here, you will find it defined as:This indicates that the property is an Optional. That means that it might contain a valid value or it might be a nil. If you are 100% sure that your cell will have this textLabel populated, then you can use the method suggested by derdida i.e:
However, as Patrick Lynch rightly pointed out, you are just setting yourself up for future run-time crashes (time bombs) if you do this to all Optionals you encounter. The best practice is to write code that will gracefully handle the case whereby an Optional is nil. In that case, the whole expression evaluates to nil. Something like this:
Although I have no infographic for this topic, a very good write-up exists here and will get you up to speed in no time. I hope that helps.
In Xcode 6.1.1 you have to unwrap both the cell and textLabel:
cell!.textLabel!.text = "your text"
try this:
And read this article about optionals here: Optionals in Swift
Update:
A better approach is now to use: