Search code examples
iosobjective-cswiftbridge

how to using swift delegate with cocoa


this is my swift code:

import UIKit

protocol ViewDelegate {
    func ViewClicked()
}

class DetailView: NSObject {
    class func display(viewName: String){

    }
    class func show(tmpDelegate: ViewDelegate?){

    }
    class func showWith2params(viewName: String,tmpDelegate: ViewDelegate?){

    }
}

this is part of my project-Swift.h generated by XCode7.0.1:

SWIFT_CLASS("_TtC15testClassMethod10DetailView")
@interface DetailView : NSObject
+ (void)display:(NSString * __nonnull)viewName;
- (nonnull instancetype)init OBJC_DESIGNATED_INITIALIZER;
@end

what should i do to use my swift class function with custom delegate parameter?


Solution

  • For making functions / classes visible in Objective see you need to make sure that u set @objc to the relevant point.

    Also in Protocol declarations :)