11
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

allocとinitについて

Last updated at Posted at 2016-11-14

allocとinit

お決まり文句で書いてて、 あまり意識してなかったのでメモ書き。

allocとは

・変数を生成するにあたってメモリを確保すること。
MyClass *myClass;
myClass = [MyClass alloc];

initとは

・生成した変数にデータを保存できるようにすること。
MyClass *myClass;
myClass = [MyClass alloc];
myClass = [myClass init];

MyClass *myClass = [[MyClass alloc] init];

基本的な書き方はこれ

newが便利?

・newならばスマートに書ける。
MyClass *myClass = [MyClass new];

これで
[[MyClass alloc] init]
と同じ

11
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?