darwinkit: generate New variants based on init methods
progrium opened this issue · 0 comments
Currently we do something like this, for every init prefixed instance method, we make a class helper function that does the alloc and then calls the init method, as if it were a type method. Example: String_InitWithString
.
There are two problems with this. First, there are occasionally conflicts with actual type methods with the same name. Second, based the memory management policy, the allocator should be responsible for releasing. So these methods should autorelease just like our New functions (NewString
).
We can solve this by adding autorelease, but also naming them as New variants. This will make everything more consistent and somewhat less verbose. Instead of String_InitWithString
we'd have NewStringWithString
. That particular example is redundant, but usually it won't be. The rule would be take the method name after init
and add it to the New method.