swift-optionals

How to create a generic function in Swift that will reject the given parameter unless it is an Optional?

旧巷老猫 提交于 2020-05-17 06:56:06
问题 This question is a follow up to my earlier question: I expected the system to report non protocol conformance, but it does not! Why? Please read the referred question for you to get a better idea of the constraints at hand. I created a generic function in Swift that will reject its parameter unless such a parameter is Optional . The function I created fully works and does what I desire. Meaning, any calls to onlyCallableByAnOptable(...) , even inside an if let , will yield error due to non

I expected the system to report non protocol conformance, but it does not! Why?

巧了我就是萌 提交于 2020-03-22 09:06:39
问题 I am using Xcode Version 11.3.1 (11C504) I am trying to create a generic function in Swift that will reject its parameter unless such a parameter is Optional. In the following code, I was expecting the system to report errors in all calls to onlyCallableByAnOptable() made inside test() , because none of them provide an optional value as a parameter. However, the system only reports non-protocol conformance if I remove the Optional extension that conforms to Optable ! Which to me, it means