1

I am using an Objective-C library. It has a protocol as

@protocol RNFrostedSidebarDelegate <NSObject>
@optional
- (void)sidebar:(RNFrostedSidebar *)sidebar didTapItemAtIndex:(NSUInteger)index;
- (void)sidebar:(RNFrostedSidebar *)sidebar didEnable:(BOOL)itemEnabled itemAtIndex:(NSUInteger)index;
@end

I am trying to implement it in Swift. How should I write this func?

DANG Fan
  • 854
  • 11
  • 21

2 Answers2

4

this would be a Swift class implementing the protocol

class MyForstedSidebarDelegate : RNFrostedSidebarDelegate {

    func sidebar(sidebar: RNFrostedSidebar, didTapItemAtIndex index: UInt) {
        ... do stuff ...
    }

    func sidebar(sidebar: RNFrostedSidebar, didEnable itemEnabled: Bool, itemAtIndex index: UInt) {
        ... do stuff ...
    }

}
Alexander Battisti
  • 2,178
  • 2
  • 19
  • 24
0

something like this could be similar to your original concept:

@objc protocol RNFrostedSidebarDelegate {
    @optional func sideBarDidTapItem(sidebar: RNFrostedSidebar, index: UInt) -> ()
    @optional func sideBarDidEnable(sidebar: RNFrostedSidebar, itemEnabled: Bool, index: UInt) -> ()
}
holex
  • 23,961
  • 7
  • 62
  • 76