Passing nil into non-optional parameter in Swift method produces unhelpful error message
| Originator: | sethfri | ||
| Number: | rdar://20648463 | Date Originated: | 04/22/2015 |
| Status: | Open | Resolved: | No |
| Product: | Developer Tools | Product Version: | Xcode 6.3.1, OS X 10.10.3 |
| Classification: | Enhancement | Reproducible: | n/a |
Summary:
I wrote a Swift method:
func scheduleLocalNotificationForArrivalTime(arrivalTime: Int, routeName: String, stopName: String, fromViewController viewController: UIViewController) {}
In my test bundle, I tried to exercise this function by calling it with the following:
scheduleLocalNotificationForArrivalTime(4, "Black Route", "Branscomb Quad", nil)
When I tried to build this, I got the attached error. It took me around a half hour to realize it was because I hadn't declared the viewController parameter as an optional. I couldn't understand why this wouldn't compile; the argument list seemed exactly as I defined it and exactly as I was calling it.
Xcode could provide a much more helpful error message, like "cannot pass nil value into non-optional parameter". That would have allowed me to instantly realize what the problem was.
Steps to Reproduce:
1. Write method with no optional parameters
2. Call the method, and try to pass nil into one of the parameters
3. See attached error
Expected Results:
A helpful error message when I try to pass nil into a non-optional parameter
Actual Results:
A very vague error message when I try to pass nil into a non-optional parameter
Version:
Xcode 6.3.1, OS X 10.10.3
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!