You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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 haveNewStringWithString
. That particular example is redundant, but usually it won't be. The rule would be take the method name afterinit
and add it to the New method.The text was updated successfully, but these errors were encountered: