生きているものたち
科学者のためのCocoa(パートIII): 生きているもの
英語のチュートリアルの作成日:2006年11月20日
著者:Drew McCormack
英語のチュートリアル:MacResearch.org
翻訳:Ignacio Enriquez
私たちってどういう風に創造されましたか?いつ滅ぼされるでしょうか? 最近なぜこんなに忘れっぽくなりましたか?この全ての質問は重要であります。しかしながら、今日(または近い未来に)一つも答えることができません。ですが、これらは科学者のためのCocoaのシリーズに関係しています:オブジェクトのライブサイクルです。オブジェクトはどうやって生まれるか?いつ削除されるか?そして、どのように自分自身を解放するのか?
最後ですが、もっとも重要なのは、最近なぜこんなに忘れっぽくなったのか?... いや違う!...どのようにCocoaはプログラムのメモるの管理を行うかというのです。
How did we get created? When will we be destroyed? Why am I so forgetful lately? Important questions all. Unfortunately we will not answer any of them today (or in the future for that matter), but they are related to the topic of this installment of the Cocoa for Scientists series: object life-cycle. How does an object get born? When does it get deleted, and how does it deallocate itself? And, last but by no means least: Why am I so forgetful lately...no...how does a Cocoa program manage its memory use?
オブジェクトのメモリの割当と初期化
Allocating and Initializing Objects
前回はクラスについて学びました。クラスはテンプレートみたいに、オブジェクトを作ることに使うのです。クラスはデータと同じクラスに属するオブジェクトが使えるメソッドを定義します。例えば、スティーブジョブズは人間であります(ある人物はスパー人間だと主張するし、ほかの者がそれ以下だと言います。見ている視点から変わってくるかと思いますが、それは置いておきましょう)。
アプリケーションでは、クラス人間があるとしますと スティーブジョブズはそのクラスのインスタンスになります。またはそのクラスのオブジェクトです。クラスには名前と名字の様な どんなものが含まれるかを定義することができます。
そのクラスをインスタンス化すると、様々な人(人間)を意味する様々なオブジェクトが作られます。
Last time we learned about classes. Classes are like a template that can be used to create objects. A class describes the data and methods that objects of that type contain. For example, Steve Jobs is human (some may argue that he is super-human — or sub-human, depending on your viewpoint — but let's leave that to one side). In an application, we may have a class Human, and Steve Jobs could be an instance or object of that class. The class would detail what an object should include, such as a first and last name. By instantiating that class, you can create different objects representing different human beings.
プログラマーの一ついいことは、神を演ずることができます。なにかが生成するか、消えるかを貴方が決めます。Cocoaでは新しいオブジェクトの作成をするには、メモリ領域の確保をします。そして、インスタンス変数の初期化をします。多くの別の言語では、上記の2つのことが一つになっていますが、Cocoaでは様々なフェーズがあります。
One cool thing about being a programmer is that you get to play God. You get to say when something comes into existence, and when it is obliterated. In Cocoa, you create a new object by allocating memory for it to use, and then initializing its instance variables. In many other languages, these two things are rolled into one, but in Cocoa they are distinct phases.
前回のチュートリアルのサンプルのAdditionOperatorを触れながらこれはどんなことかを見てみましょう、特にmain関すでoperatorの作成のところ:
Let's see how this works by returning to the simple AdditionOperator class from the last tutorial, in particular the place in the main function where the operator was created:
AdditionOperatorのオブジェクトを作成するために まずは、allocを呼び出します。そしてinitWithLeftValue:andRightValue:を呼び出します。allocはスーパークラス(NSObject)にあります。
何をするかというと、新しいオブジェクトに必要なメモリ領域の確保をするだけです。どういう風に確保するかを分かる必要がなく、自分のallocメソッドを書く必要が決してないでしょう。オブジェクトの作成をする度に呼び出す必要があることだけを知っていればいいです。
In order to create an AdditionOperator object, first a call is made to alloc, and then a call is made to initWithLeftValue:andRightValue:. alloc can be found in the superclass, NSObject. All it does is allocate memory for the new object. You don't really need to know how it does this, and you virtually never need to write your own alloc method. You just need to know to call it every time you need a new instance of a class.
allocはAdditionOperatorのデータの格納に必要なメモリ領域を返してくれますが、データにはなにも入れません。インスタンス変数を初期化をするために初期化メソッドが呼び出されます。この場合、initWithLeftValue:andRightValue:。前回、初期化メソッドの説明を言い紛らしたが、今回はちゃんとします。以下は典型的な初期化メソッドです:
alloc returns a chunk of memory big enough to store the data of the AdditionOperator, but it doesn't give that data any value. To initialize the instance variables, an initializer method is called, in this case initWithLeftValue:andRightValue:.
Last time I glossed over the initializer, but this time I want to do it justice. Here is the typical form of an initializer:
この間のチュートリアルと全く一緒ではないと思っている人もいるかと思います。確かにそうですね。前回は、分かりやすいもののみを入れたからです。しかし、今回は 普通のCocoaアプリケーションで見るような初期化メソッドを見せたかったからです。
The perceptive ones in the audience may point out that this is not exactly the same as the initializer from the last tutorial. True. Last time I just wanted to include something easy to understand, but this time I want to present a real initializer, as you would find it in a typical Cocoa application.
前者のバージョンとの違いはif文のことです。Cocoaはコンベンションに準するフレームワークであります。それらのコンベンションに準したらよ大丈夫です。準しなかったら今後痛い目に合うかもしれません。これはコンベンションの一つの例です:初期化メソッドは 初期化に何か問題があったときにnil(ゼロと同じようなもの)あるいはCの定数NULLを返します。ですので、一般に初期かの直後にnilが返ってきたかをチェックします。
The difference with the former version of the class lies in the if block. Cocoa is a framework built upon conventions. If you stick to the conventions, you will be fine; if you flout them, it will hurt. This is an example of a Cocoa convention: An initializer will return the constant nil — which is similar to a zero, or the C constant NULL — whenever something goes wrong in the initialization. So, in general, you should check the return value to see if it is nil after you call an initializer.
自分の初期化メソッドでは(super変数を介して)スパークラスを呼び出すことが重要です。なぜかというと、(スーパークラスの全てのインスタンス変数とメソッドを継承したことを思い出しましょう!)もしスーパークラスを呼び出さなかったら、それらのインスタンス変数がそのまま初期化されないからです。
It is important that you always call the superclass (via the super variable) in your own initializers. Why? Because you have to remember that you have inherited all the instance variables and methods of the superclass. If you don't chain to the superclass, the data in that class will remain uninitialized.
しかし、if文のことをまだ説明していません。まず、self変数(現在初期化しようとしているオブジェクトへのポインタ)にスーパークラスNSObjectのinitメソッドの結果が割り当てられます。そして、その結果がnilであるかがチェックされます。
But that doesn't explain everything about this if block. First, the self variable, which you will recall is a pointer to the object being initialized, is assigned to the return value of invoking the init method of the superclass (NSObject), and then the value of self is tested to see if it is nil.
なぜselfはこのような割り当て方をされるかというと、Cocoaにはまた別なコンベンションがあり、元々確保したオブジェクトを捨てて新しいオブジェクトを確保して返してもいいというのです。なんでこういう風にするかと今は説明しませんが、(本当に意味があるかという議論もありますし)一応アップルが推奨しているので、今回はそれに準します。
The reason self gets assigned in this way is that Cocoa has a second convention that says that an initializer is allowed to throw away the originally allocated object, and allocate a new one. We will not discuss why you would do this at this stage, but given that it is allowed, the assignment of self to the return value of the super class initializer has you covered. (There is actually some debate about whether this convention makes any sense, but given it has Apple's endorsement, we will stick with it here.)
もしsuperのinitメソッドが正常に完了したら、self変数はnilになりません。そうするとifブロックの中のコードが実行されます。
このブロックにはAdditionOperatorの2つのインスタンス変数が初期化されます。
初期化メソッドの最後の行はselfオブジェクトを返します。初期化メソッドは必ず初期化されたオブジェクトを返します。スパークラスの初期化メソッドでなにか上手くいかなかった場合にselfがnilになります。そしてnilも返り値になり、initWithLeftValue:andRightValue:の返り値にもなります。
If super's init method succeeds, the self variable will not be nil, and the block of code after the if will get executed. This block initializes the two instance variables of the AdditionOperator object. The last line of the initializer returns the self object. An initializer always returns the object it initializes. Note that if something had gone wrong in the superclass initializer, self would be nil, and nil would also be the return value of initWithLeftValue:andRightValue:.
指定された初期化メソッド
The Designated Initializer
実は、一つのクラスは複数の初期化メソッドを持つことができます。状況によって使用される初期化メソッドが変わってくることもあるますから。例えば、FoundationフレームワークのNSData(生データを格納するために使われるクラス)initWithContentsOfFile:を使ってファイルのデータから初期化することができますし、initWithBytes:length:を使って既存のバイトのバッファーからも初期化できます。
そこで、スパークラスの初期化メソッドの中でどれを使うべきかと疑問があるかと思います。
A class can actually have many different initializers. Different initializers may be used for different circumstances. For example, the Foundation class NSData, which can be used to store a block of raw data, can be initialized with the data from a file by invoking the initializer initWithContentsOfFile:, or with a pre-existing buffer of bytes by invoking initWithBytes:length:. This raises the question: Which superclass initializer should you invoke from your initializer method?
答えはCocoaが提供してくれます。(予想はしているかと思いますが)また別のコンベンションです。Cocoaには指定された初期化メソッド(The Designated Initializer)の概念があります。サブクラスからよく呼ぶときに 一般的にこれを使うべきでしょう。指定された初期化メソッドの為の言語のサポートはありませんし、単純なコンベンションです。コンベンションだから大体ドキュメンテーションやコメントにしか影響がなりません。
Well, Cocoa has an answer for you here too, and it again comes down to — you guessed it — convention. Cocoa has the concept of a designated initializer, which is the initializer you should generally chain to from a subclass. There is no language support for the designated initializer; it is purely a convention, and, as such, typically involves no more than a statement to the effect in the comments or documentation.
重要な指定された初期化メソッドの一つはNSObjectのinitメソッドです。大抵の場合は自分のクラスはNSObjectを継承し AdditionOperatorの様にスパークラスを使
One of the more important designated initializers is the init method of the NSObject class. More often than not, your own classes will inherit from NSObject, and just as in AdditionOperator, you should chain to that method of the superclass.
Deallocating Objects
The flip side of allocation and initialization is deallocation. What happens when you destroy an object? In Cocoa, when an object is ready to disappear, the method dealloc gets called, which is inherited from NSObject. Anything that needs to happen when the object is no longer needed should happen here. For example, any memory that has been dynamically allocated for the object should be deallocated. Resources like open files should also be released.
The version of the AdditionOperator class from last time didn't need to include a dealloc method, because it didn't need to do anything special when deleted, but we can easily modify it so that dealloc is needed. For example, let's assume the interface of AdditionOperator is like so:
The class implementation would be:
The biggest change, however, is the introduction of a dealloc method. This is needed to destroy the NSNumber objects that were allocated in the initializer. If you don't do this, you get a memory leak, with the NSNumber objects remaining in existence until the program exits.
The form of the dealloc method above is quite typical. Usually, a number of objects are 'released', and then the dealloc method of the superclass is invoked so that it can do any cleaning up it needs to. You may be wondering why the release method is called for the two NSNumbers, rather than the dealloc method. This is part of Cocoa's memory management system, which will be explained in detail next time. For now, the short answer is: release will call the dealloc method for you, but it first checks to make sure no other objects need to use the NSNumbers.
Summary of Patterns
That's basically it for this time, but before finishing, I just want to impress on you one more time the basic form of an initializer and a deallocator in Cocoa.
If you are wondering whether we will ever get to make a Cocoa app with Xcode and Interface Builder, be patient. You can't really do that stuff effectively unless you understand the basics of Cocoa classes. We'll get to graphical interfaces and move into Xcode after a couple more tutorials, and then the fun will really begin.
英語のチュートリアルの作成日:2006年11月20日
著者:Drew McCormack
英語のチュートリアル:MacResearch.org
翻訳:Ignacio Enriquez
私たちってどういう風に創造されましたか?いつ滅ぼされるでしょうか? 最近なぜこんなに忘れっぽくなりましたか?この全ての質問は重要であります。しかしながら、今日(または近い未来に)一つも答えることができません。ですが、これらは科学者のためのCocoaのシリーズに関係しています:オブジェクトのライブサイクルです。オブジェクトはどうやって生まれるか?いつ削除されるか?そして、どのように自分自身を解放するのか?
最後ですが、もっとも重要なのは、最近なぜこんなに忘れっぽくなったのか?... いや違う!...どのようにCocoaはプログラムのメモるの管理を行うかというのです。
How did we get created? When will we be destroyed? Why am I so forgetful lately? Important questions all. Unfortunately we will not answer any of them today (or in the future for that matter), but they are related to the topic of this installment of the Cocoa for Scientists series: object life-cycle. How does an object get born? When does it get deleted, and how does it deallocate itself? And, last but by no means least: Why am I so forgetful lately...no...how does a Cocoa program manage its memory use?
オブジェクトのメモリの割当と初期化
Allocating and Initializing Objects
前回はクラスについて学びました。クラスはテンプレートみたいに、オブジェクトを作ることに使うのです。クラスはデータと同じクラスに属するオブジェクトが使えるメソッドを定義します。例えば、スティーブジョブズは人間であります(ある人物はスパー人間だと主張するし、ほかの者がそれ以下だと言います。見ている視点から変わってくるかと思いますが、それは置いておきましょう)。
アプリケーションでは、クラス人間があるとしますと スティーブジョブズはそのクラスのインスタンスになります。またはそのクラスのオブジェクトです。クラスには名前と名字の様な どんなものが含まれるかを定義することができます。
そのクラスをインスタンス化すると、様々な人(人間)を意味する様々なオブジェクトが作られます。
Last time we learned about classes. Classes are like a template that can be used to create objects. A class describes the data and methods that objects of that type contain. For example, Steve Jobs is human (some may argue that he is super-human — or sub-human, depending on your viewpoint — but let's leave that to one side). In an application, we may have a class Human, and Steve Jobs could be an instance or object of that class. The class would detail what an object should include, such as a first and last name. By instantiating that class, you can create different objects representing different human beings.
プログラマーの一ついいことは、神を演ずることができます。なにかが生成するか、消えるかを貴方が決めます。Cocoaでは新しいオブジェクトの作成をするには、メモリ領域の確保をします。そして、インスタンス変数の初期化をします。多くの別の言語では、上記の2つのことが一つになっていますが、Cocoaでは様々なフェーズがあります。
One cool thing about being a programmer is that you get to play God. You get to say when something comes into existence, and when it is obliterated. In Cocoa, you create a new object by allocating memory for it to use, and then initializing its instance variables. In many other languages, these two things are rolled into one, but in Cocoa they are distinct phases.
前回のチュートリアルのサンプルのAdditionOperatorを触れながらこれはどんなことかを見てみましょう、特にmain関すでoperatorの作成のところ:
Let's see how this works by returning to the simple AdditionOperator class from the last tutorial, in particular the place in the main function where the operator was created:
AdditionOperator *operator = [[AdditionOperator alloc] initWithLeftValue:4.0 andRightValue:5.0];
AdditionOperatorのオブジェクトを作成するために まずは、allocを呼び出します。そしてinitWithLeftValue:andRightValue:を呼び出します。allocはスーパークラス(NSObject)にあります。
何をするかというと、新しいオブジェクトに必要なメモリ領域の確保をするだけです。どういう風に確保するかを分かる必要がなく、自分のallocメソッドを書く必要が決してないでしょう。オブジェクトの作成をする度に呼び出す必要があることだけを知っていればいいです。
In order to create an AdditionOperator object, first a call is made to alloc, and then a call is made to initWithLeftValue:andRightValue:. alloc can be found in the superclass, NSObject. All it does is allocate memory for the new object. You don't really need to know how it does this, and you virtually never need to write your own alloc method. You just need to know to call it every time you need a new instance of a class.
allocはAdditionOperatorのデータの格納に必要なメモリ領域を返してくれますが、データにはなにも入れません。インスタンス変数を初期化をするために初期化メソッドが呼び出されます。この場合、initWithLeftValue:andRightValue:。前回、初期化メソッドの説明を言い紛らしたが、今回はちゃんとします。以下は典型的な初期化メソッドです:
alloc returns a chunk of memory big enough to store the data of the AdditionOperator, but it doesn't give that data any value. To initialize the instance variables, an initializer method is called, in this case initWithLeftValue:andRightValue:.
Last time I glossed over the initializer, but this time I want to do it justice. Here is the typical form of an initializer:
-(id)initWithLeftValue:(double)lv andRightValue:(double)rv {
if ( self = [super init] ) {
leftValue = lv;
rightValue = rv;
}
return self;
}
この間のチュートリアルと全く一緒ではないと思っている人もいるかと思います。確かにそうですね。前回は、分かりやすいもののみを入れたからです。しかし、今回は 普通のCocoaアプリケーションで見るような初期化メソッドを見せたかったからです。
The perceptive ones in the audience may point out that this is not exactly the same as the initializer from the last tutorial. True. Last time I just wanted to include something easy to understand, but this time I want to present a real initializer, as you would find it in a typical Cocoa application.
前者のバージョンとの違いはif文のことです。Cocoaはコンベンションに準するフレームワークであります。それらのコンベンションに準したらよ大丈夫です。準しなかったら今後痛い目に合うかもしれません。これはコンベンションの一つの例です:初期化メソッドは 初期化に何か問題があったときにnil(ゼロと同じようなもの)あるいはCの定数NULLを返します。ですので、一般に初期かの直後にnilが返ってきたかをチェックします。
The difference with the former version of the class lies in the if block. Cocoa is a framework built upon conventions. If you stick to the conventions, you will be fine; if you flout them, it will hurt. This is an example of a Cocoa convention: An initializer will return the constant nil — which is similar to a zero, or the C constant NULL — whenever something goes wrong in the initialization. So, in general, you should check the return value to see if it is nil after you call an initializer.
自分の初期化メソッドでは(super変数を介して)スパークラスを呼び出すことが重要です。なぜかというと、(スーパークラスの全てのインスタンス変数とメソッドを継承したことを思い出しましょう!)もしスーパークラスを呼び出さなかったら、それらのインスタンス変数がそのまま初期化されないからです。
It is important that you always call the superclass (via the super variable) in your own initializers. Why? Because you have to remember that you have inherited all the instance variables and methods of the superclass. If you don't chain to the superclass, the data in that class will remain uninitialized.
しかし、if文のことをまだ説明していません。まず、self変数(現在初期化しようとしているオブジェクトへのポインタ)にスーパークラスNSObjectのinitメソッドの結果が割り当てられます。そして、その結果がnilであるかがチェックされます。
But that doesn't explain everything about this if block. First, the self variable, which you will recall is a pointer to the object being initialized, is assigned to the return value of invoking the init method of the superclass (NSObject), and then the value of self is tested to see if it is nil.
なぜselfはこのような割り当て方をされるかというと、Cocoaにはまた別なコンベンションがあり、元々確保したオブジェクトを捨てて新しいオブジェクトを確保して返してもいいというのです。なんでこういう風にするかと今は説明しませんが、(本当に意味があるかという議論もありますし)一応アップルが推奨しているので、今回はそれに準します。
The reason self gets assigned in this way is that Cocoa has a second convention that says that an initializer is allowed to throw away the originally allocated object, and allocate a new one. We will not discuss why you would do this at this stage, but given that it is allowed, the assignment of self to the return value of the super class initializer has you covered. (There is actually some debate about whether this convention makes any sense, but given it has Apple's endorsement, we will stick with it here.)
もしsuperのinitメソッドが正常に完了したら、self変数はnilになりません。そうするとifブロックの中のコードが実行されます。
このブロックにはAdditionOperatorの2つのインスタンス変数が初期化されます。
初期化メソッドの最後の行はselfオブジェクトを返します。初期化メソッドは必ず初期化されたオブジェクトを返します。スパークラスの初期化メソッドでなにか上手くいかなかった場合にselfがnilになります。そしてnilも返り値になり、initWithLeftValue:andRightValue:の返り値にもなります。
If super's init method succeeds, the self variable will not be nil, and the block of code after the if will get executed. This block initializes the two instance variables of the AdditionOperator object. The last line of the initializer returns the self object. An initializer always returns the object it initializes. Note that if something had gone wrong in the superclass initializer, self would be nil, and nil would also be the return value of initWithLeftValue:andRightValue:.
指定された初期化メソッド
The Designated Initializer
実は、一つのクラスは複数の初期化メソッドを持つことができます。状況によって使用される初期化メソッドが変わってくることもあるますから。例えば、FoundationフレームワークのNSData(生データを格納するために使われるクラス)initWithContentsOfFile:を使ってファイルのデータから初期化することができますし、initWithBytes:length:を使って既存のバイトのバッファーからも初期化できます。
そこで、スパークラスの初期化メソッドの中でどれを使うべきかと疑問があるかと思います。
A class can actually have many different initializers. Different initializers may be used for different circumstances. For example, the Foundation class NSData, which can be used to store a block of raw data, can be initialized with the data from a file by invoking the initializer initWithContentsOfFile:, or with a pre-existing buffer of bytes by invoking initWithBytes:length:. This raises the question: Which superclass initializer should you invoke from your initializer method?
答えはCocoaが提供してくれます。(予想はしているかと思いますが)また別のコンベンションです。Cocoaには指定された初期化メソッド(The Designated Initializer)の概念があります。サブクラスからよく呼ぶときに 一般的にこれを使うべきでしょう。指定された初期化メソッドの為の言語のサポートはありませんし、単純なコンベンションです。コンベンションだから大体ドキュメンテーションやコメントにしか影響がなりません。
Well, Cocoa has an answer for you here too, and it again comes down to — you guessed it — convention. Cocoa has the concept of a designated initializer, which is the initializer you should generally chain to from a subclass. There is no language support for the designated initializer; it is purely a convention, and, as such, typically involves no more than a statement to the effect in the comments or documentation.
重要な指定された初期化メソッドの一つはNSObjectのinitメソッドです。大抵の場合は自分のクラスはNSObjectを継承し AdditionOperatorの様にスパークラスを使
One of the more important designated initializers is the init method of the NSObject class. More often than not, your own classes will inherit from NSObject, and just as in AdditionOperator, you should chain to that method of the superclass.
Deallocating Objects
The flip side of allocation and initialization is deallocation. What happens when you destroy an object? In Cocoa, when an object is ready to disappear, the method dealloc gets called, which is inherited from NSObject. Anything that needs to happen when the object is no longer needed should happen here. For example, any memory that has been dynamically allocated for the object should be deallocated. Resources like open files should also be released.
The version of the AdditionOperator class from last time didn't need to include a dealloc method, because it didn't need to do anything special when deleted, but we can easily modify it so that dealloc is needed. For example, let's assume the interface of AdditionOperator is like so:
#import <Foundation/Foundation.h>
@interface AdditionOperator : NSObject {
NSNumber *leftValue;
NSNumber *rightValue;
}
-(id)initWithLeftValue:(double)lv andRightValue:(double)rv;
-(double)evaluate;
@end
NSNumber is a class in the Foundation framework that can be used to store decimal and other types of numbers.The class implementation would be:
@implementation AdditionOperator
-(id)initWithLeftValue:(double)lv andRightValue:(double)rv {
if ( self = [super init] ) {
leftValue = [[NSNumber alloc] initWithDouble:lv];
rightValue = [[NSNumber alloc] initWithDouble:rv];
}
return self;
}
-(void)dealloc {
[leftValue release];
[rightValue release];
[super dealloc];
}
-(double)evaluate {
return [leftValue doubleValue] + [rightValue doubleValue];
}
@end
The initializer has been modified to convert the doubles passed into NSNumber objects. Note that the same allocation and initialization pattern is used to create the NSNumbers as is used to create the AdditionOperator itself. The evaluate method has also been updated slightly, because now it must retrieve the double values (using the doubleValue method) from the leftValue and rightValue objects before they can be added.The biggest change, however, is the introduction of a dealloc method. This is needed to destroy the NSNumber objects that were allocated in the initializer. If you don't do this, you get a memory leak, with the NSNumber objects remaining in existence until the program exits.
The form of the dealloc method above is quite typical. Usually, a number of objects are 'released', and then the dealloc method of the superclass is invoked so that it can do any cleaning up it needs to. You may be wondering why the release method is called for the two NSNumbers, rather than the dealloc method. This is part of Cocoa's memory management system, which will be explained in detail next time. For now, the short answer is: release will call the dealloc method for you, but it first checks to make sure no other objects need to use the NSNumbers.
Summary of Patterns
That's basically it for this time, but before finishing, I just want to impress on you one more time the basic form of an initializer and a deallocator in Cocoa.
-(id)init... {
// Chain to designated initializer of superclass
if ( self = [super init] ) {
...
}
return self;
}
-(void)dealloc {
...
[super dealloc];
}
If you can internalize that, you are ready for the next step, Memory Management, which will be the topic of the next discussion.If you are wondering whether we will ever get to make a Cocoa app with Xcode and Interface Builder, be patient. You can't really do that stuff effectively unless you understand the basics of Cocoa classes. We'll get to graphical interfaces and move into Xcode after a couple more tutorials, and then the fun will really begin.
コメント
コメントを投稿