UITextField's text property never produces nil
| Originator: | NathanHosselton | ||
| Number: | rdar://32937801 | Date Originated: | 6/22/2017 |
| Status: | Duplicate/25780524 (Open) | Resolved: | Closed as duplicate 7/5/2017 |
| Product: | iOS + SDK UIKit | Product Version: | Xcode 9 beta 2 |
| Classification: | Bug | Reproducible: | Always |
Although UITextField's API indicates that its `text` property is an optional string (String?), in practice it never produces nil. If there is no text programmatically assigned to an instance, or entered by a user, its `text` property will return an empty string which must be unwrapped. As mentioned, this contradicts its API, which could lead to bugs or unexpected behavior. At best, it creates an annoyance in handling the unnecessary optional. Steps to Reproduce: let foo = UITextField() foo.text == nil foo.text = nil foo.text == nil Expected Results: Both nil checks produce true Observed Results: Both nil checks produce false iOS Version/Build: Latest iOS SDK as of Xcode 9 beta 2, but I've personally confirmed back to Xcode 8.3 and a search of open radars shows the related radar 25780524 which was opened April 18th 2016, so the issue could stretch back as far as Xcode 7 iOS SDKs.
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!