ios - should I avoid using new to initialize my objects? -


this question has answer here:

recently told apple discouraging use of new, , google's ios coding standards has say:

do not invoke nsobject class method new, nor override in subclass. instead, use alloc , init methods instantiate retained objects. modern objective-c code explicitly calls alloc , init method create , retain object. new class method used, makes reviewing code correct memory management more difficult.

why make reviewing code correct memory management more difficult though?

i expect reference ease of code reviews merely meant human readers of code may not notice word 'new' eyes scan on code looking alloc-init calls.

in objective-c, word 'new' shortcut calling alloc , init. cannot pass arguments; calling no-arg constructor. if later change code in such way want call 1 of other constructors , pass arguments, need change "new" alloc-init. common enough yet anothe reason avoid calling 'new' in first place.

there no advantage calling 'new' on calling alloc-init. 'new' word in objective-c because other languages such java use keyword.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -