NSIndexPath objects are uniqued and shared.
Yes, that's it. All the NSIndexPath objects that have the same value are UNIQUED and SHARED. What do these 2 words mean to an NSIndexPath object? That means if you have an index path refer to a special cell, let's say row 2 and section 1, you can create an index path by yourself, and it should be equal to the one generated by system.
In another word, you can use if (myIndexPath == systemIndexPath) to compare 2 index path instead of if (myIndexPath.row == systemIndexPath.row && myIndexPath.section == systemIndexPath.section). Isn't that much easy to understand?
NSIndexPath[Class Reference] はFoundationの中にある特別なクラスだ、UIKit はそれの上にUITableView[See NSIndexPath UIKit Additions]で使いやすくなるような便利なメソッドを追加した。普通は、indexPath.rowとindexPath.sectionのように使っている。ただし、このクラスの特徴を思えておくと、非常に綺麗なコードを書ける。
NSIndexPath のオブジェクトは唯一であり、共有している.
そう、これだけだ。全ての同じ値を持っているNSIndexPathのオブジェクトは唯一であり、共有されいる。どういう意味?つまり、あなたが作ったIndex Pathオブジェクトとシステムが作られたIndex Pathが同じPath(例えば、sectionの1とrowの2)を指している場合、同じオブジェクトのはずだ。
言い換えると、この書き方を使えば、IndexPathの値比較は可能だ: if (myIndexPath == systemIndexPath) 、逆に、この書き方が要らないよ: if (myIndexPath.row == systemIndexPath.row && myIndexPath.section == systemIndexPath.section). これは便利だろう!
----
追加: NSIndexPathの文書に書いてある説明用の図
1.4.3.2

No comments:
Post a Comment