This is fascinating - I don’t think this was possible in Swift, so thank you for posting it! I’m going to give it a try in a library I’m writing next week.
1 Like
It's been out there a while; I think I came up with it first while helping someone in the WWDC 2014 labs. Surprised more people don't know about it!
1 Like
Is there an easy way to verify that it only allocates space for a single class instance?
In other words, the part where it reassigns self, can we verify that the compiler did not actually allocate space for Self instance prior to that, only to then deallocate it after the reassignment?
swiftc -S FactoryInitializable.swift | xcrun swift-demangle and compare the code for testMe1 and testMe2
1 Like