0

I've a simple question about objective-c / objective-j syntax.

This is a method dataForItemsAtIndexes and it gets as parameters a CPIndextSet and CPString. It should return a CPData object. However I don't understand what's (CPCollectionView)aCollectionView.

- (CPData)collectionView:(CPCollectionView)aCollectionView
   dataForItemsAtIndexes:(CPIndexSet)indices
                 forType:(CPString)aType

Thanks

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
aneuryzm
  • 63,052
  • 100
  • 273
  • 488

1 Answers1

1

That identifies the CPCollectionView which your implementing data source corresponds to. This is useful in case your view or window has multiple CPCollectionViews, whose data sources are the same object, so it knows which view to provide which data to.

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
  • @BoltClock uhm, so are CPData and CPCollectionView both returned by the method ? Is CPCollectionView children of CPData ? If yes, why do they specify CPData ? – aneuryzm Dec 20 '10 at 13:38
  • @Patrick: Nope, the method only returns a `CPData`. The `CPCollectionView` is passed in as an argument so you can obtain information about it within your delegate method. So in essence there are really *three* parameters: the collection view, the index set and the type string. – BoltClock Dec 20 '10 at 13:39
  • @BoltClock All right, now it makes sense. However I'm a bit confused with the methods signature. Can parameters be specified before the method names ? (If so, why ?) Here aCollectionView is placed before the method name dataForItemsAtIndexes, right ? – aneuryzm Dec 20 '10 at 20:44
  • @Patrick: The method name is actually made up of all the parameter names. In this case, the method is called `collectionView:dataForItemsAtIndexes:forType:` (notice the colons to represent the three parameters). The word that immediately follows the return type is the start of the method name. – BoltClock Dec 20 '10 at 20:47
  • @BoltClock wow, so there is not method name ? I thought you need a method name, at least this is what I've read on wikipedia: -(return_type)method_name:(param1_type)param1_varName – aneuryzm Dec 20 '10 at 20:52
  • @BoltClockWhat happens if you need 2 methods with the same arguments, if you don't specify method names ? thanks – aneuryzm Dec 20 '10 at 20:53
  • @Patrick: No, like I said the entire thing is the method name. Here, `method_name:(param1_type)param1_varName` is `collectionView:(CPCollectionView *)aCollectionView`. – BoltClock Dec 20 '10 at 20:53
  • @Patrick: to have two methods with the same parameter types just name the left sides of each parameter expression differently. – BoltClock Dec 20 '10 at 20:56