4 ms·
Honestly the syntax is a lot simpler and rewriting in Objective-C would probably in some cases get more bulky if you are transitioning to using typed collection
by morbidhawk 11y ago
Honestly the syntax is a lot simpler and rewriting in Objective-C would probably in some cases get more bulky if you are transitioning to using typed collections:
NSMutableDictionary<NSString *, NSString *> *dictionary = [[NSMutableDictionary<NSString *, NSString *> alloc] init];
compared to the swift version:
var dictionary = [String:String]()
- trhway 11y ago>the syntax is a lot simpler and the flexibility is less too. The expressions are far from being equivalent. The Objective-C expression specifies what kind of dictionary interface and implementation will be there, where is the Swift's versions says there will be just Swift's map. Ability to manage implementation may for example start to matter once you're off beaten path - like large number of items, high concurrency or some very specific requirements on life cycle, memory or performance or you want/have to exploit very specific type/set of keys. Though in mainstream case general standard implementation is probably just fine. Everybody chooses their own poison.
- klausa 11y agoyou could just say [NSMutableDictionary dictionary] instead of -alloc -init on the annotated class.
- deleted 11y ago[deleted]
- morbidhawk 11y agoThat's true. The rhs isn't the the most obtrusive part compared to its type declaration: NSMutableDictionary<NSString *, NSString *> * imagine having to pass the typed dictionary into a method, now you've got to add the type declaration to the method signature in addition to it being initialized elsewhere. Its brutal but also worth doing if you stick to Objc.