Returning immutable Objective-C collections when converting from C++
The specified `ObjcType` in all of these is the immutable counterpart (`NSArray,` `NSSet`, and `NSDictionary`) so returning a mutable instance was unnecessary. This has a few added benefits: - **Guarantees immutability**: even though the types were immutable, one can (though obviously discouraged) mutate the instances. - **Optimizes memory usage**: it's common in Objective-C to perform *defensive copying* (I've seen Djinni does this in a few places). By copying early we guarantee that only one copy is made, rather than each class creating its own copy (remember that calling `-copy` on an immutable instance simply returns `this`). - **Optimizes performance**: immutable implementations of these classes in `Foundation` are potentially better optimized for searching and fetching, since they don't need to be optimized for insertion, deletion, or update.
Showing
Please register or sign in to comment