0

I have an iOS app that uses a UICollectionView. I am now creating the app for Mac so I am trying to use NSCollectionView however I am not sure where I should start. I am trying to add the code below but it does not seem to be available. Where am I going wrong? Thanks

func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {

return 30

}


func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
    let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as ProjectsCellCollectionViewCell

cell.textLabel.text = "\(indexPath.section):\(indexPath.row)"

    return cell
}

Thanks.

I have followed the Quick Start Guide and I am stuck at this part:

-(void)insertObject:(PersonModel *)p inPersonModelArrayAtIndex:(NSUInteger)index {
[personModelArray insertObject:p atIndex:index];
}

-(void)removeObjectFromPersonModelArrayAtIndex:(NSUInteger)index {
[personModelArray removeObjectAtIndex:index];
}

-(void)setPersonModelArray:(NSMutableArray *)a {
personModelArray = a;
}

-(NSArray*)personModelArray {
return personModelArray;
}

I do not seem to be able to add these to my ViewController.swift file. Any suggestions?

Tom Coomer
  • 6,227
  • 12
  • 45
  • 82

1 Answers1

0

iOS uses UIKit for UI elements, while Mac uses AppKit. There are some big differences between these, mainly because iOS is for a mobile touch-based interface and Mac is for desktop keyboard/mouse interfaces. Shared between iOS and Mac is Foundation. If there's an equivalent for Mac you can often replace UI with NS to find the class you're looking for. Your code won't work because there is no UICollectionView on Mac.

However, as you already seem to have noticed, there is NSCollectionView, which Apple provide a quick start guide for.

Joseph Duffy
  • 4,566
  • 9
  • 38
  • 68
  • I have followed the guide but I am stuck at the part above in the update. – Tom Coomer Mar 21 '15 at 12:25
  • What do you mean by "I do not seem to be able to add these..."? That code is Objective-C and is purely for the model side of the collection view. You can implement the model in any way you want. – Joseph Duffy Mar 21 '15 at 12:46
  • I believe what Tom is getting at is the right way to do KVC with swift. Clearly the objective-c code won't work with swift, but they key to the question is how to get a NSCollectionview working with swift. – Bill Johnson May 23 '15 at 16:14