Even Swiftier Objective-C
Peter Steinberger and Matej Bukovinski:
In our original “Swifty Objective-C” blog post we talked about the C++
autokeyword and how it’s great for preserving type information while also making the code more readable and easier to write. This is especially true when dealing with generics or block types. Since then, Objective-C learned the same trick via the new__auto_typekeyword. Since nobody wants to type__auto_typeall day long, we decided to make things nicer by defining Swift-like macros for it.[…]
There’s only one
copyselector, and it’s not generic. It’s also not a case where returninginstancetypewould be the right fix, as there’s no general way to understand what a mutable counterpart of a class pair is called and if one even exists. […] However, we can just add that ourselves! Again, a header-only declaration that simply redefinescopyon our collections. This won’t magically add types to every single object, but it will solve the common case of (mutable) copying collections[…]
We define a block and add
__attribute__((cleanup))to it that tells the compiler to execute the function defined in that attribute. We pass along the block as a parameter and thus execute the block when the scope is exited.
Previously: Swifty Objective-C, foreach Using Objective-C Generics.
1 Comment RSS · Twitter
The only thing that came to mind: https://www.youtube.com/watch?v=I1188GO4p1E (Get Schwifty!)