-1

I tried to implement iCarousel as per this tutorial: https://medium.com/@arb1nsnmgl/icarousel-walkthrough-swift-3-0-887554155242 but when trying to implement the @protocol it gives me 4 error messages:

  1. Expected '{' in protocol type
  2. Expected an attribute name
  3. Protocol 'iCarouselDataSource' cannot be nested inside another declaration
  4. Protocols do not allow generic parameters; use associated types instead

Currently the code looks like this:

import UIKit
class ViewController: UIViewController {

@IBOutlet var carouselView: iCarousel!
override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    //Testing
    @protocol iCarouselDataSource <NSObject>
    -(NSInteger)numberOfItemsInCarousel:(iCarousel *)carousel;
    -(UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSInteger)index reusingView:(nullable UIView *)view;

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}
}
HamdyAli
  • 173
  • 3
  • 14

1 Answers1

1

You are adding it at wrong place so remove

@protocol iCarouselDataSource <NSObject>
-(NSInteger)numberOfItemsInCarousel:(iCarousel *)carousel;
-(UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSInteger)index reusingView:(nullable UIView *)view;

From viewDidLoad method.

Above methods are delegate methods. And you need to add it as shown in tutorial.

Check point 11 for that.

Also confirm the delegates as shown in point number 8.

Dharmesh Kheni
  • 71,228
  • 33
  • 160
  • 165