3 ms·
I think ObjC has left us with some dynamic habits we don't actually always need, particularly in all non-UI layers. I appreciate the way using Swift has me ques
by kylnew 10y ago
I think ObjC has left us with some dynamic habits we don't actually always need, particularly in all non-UI layers. I appreciate the way using Swift has me questioning just how much dynamism and mutability my programs really need. Overuse of things like setValue:forKey: and performSelector: have a bit of code smell anyway and there's no reason you can't replicate these kinds of behaviors, if you really need to, with Swift Dictionaries.
- Tloewald 10y agoIt seems that (a) we need Dynamic features (introspection, dynamic dispatch) and (b) we need to use it sparingly. In short, it's a _cultural_ problem, not a technical one. I suspect the solution is something as simple as a "DangerouslyCallMethodByName" method.
- mahyarm 10y agoyou could do if let method = classInstance.methods[methodKey] { //Put some ugly method argument checker thing here method.execute() } It would be typesafe, not dangerous, and statically typed.