I'm Korean android developer and new at Swift.
I am migrating my android app to ios, but meet a problem with interface and listener. I don't know how to implement listener to communicate between a custom view and a view controller.

I have a custom view(i.e. MyView) that has two buttons and each has own function.
In Android(with Java), I usually make an listener Interface in MyView and assign two functions inside like void func1( String val1 ) and func2...

```
public class MyView extends RelativeLayout {
private Button b1, b2;
private String val1, val2;

public interface OnButtonListener {
    void onFunc1(String val1);

    void onFunc2(String val2);
}

private OnButtonListener onButtonListener;

public void setOnButtonListener( OnButtonListener onButtonListener ) {
    this.onButtonListener = onButtonListener;
}

  public MyView( Context context, AttributeSet attrs ) {
    super( context, attrs );
    b1.setOnClickListener( view -> {
        if (onButtonListener != null){
            onButtonListener.onFunc1( val1 );
        }
    } );
    b2.setOnClickListener( view -> {
        if (onButtonListener != null){
            onButtonListener.onFunc1( val2 );
        }
    } );
}
}

 public class MyActivity extends Activity {
    MyView myView1, myView2;

@Override
protected void onCreate( @Nullable Bundle savedInstanceState ) {
    super.onCreate( savedInstanceState );
    myView1.setOnButtonListener( new MyView.OnButtonListener() {
        @Override
        public void onFunc1( String val1 ) {
            Log.d(TAG, val1);
        }

        @Override
        public void onFunc2( String val2 ) {
            Log.d(TAG, val2);
        }
    } );
    myView2.setOnButtonListener( new MyView.OnButtonListener() {
        @Override
        public void onFunc1( String val1 ) {
            // do something1
        }

        @Override
        public void onFunc2( String val2 ) {
            // do something2
        }
    } );
}
}

```

This code works perfectly as I wanted. So I've tried to apply same pattern into Swift, but I couldn't find any way to do.

below is for swift 4

```
import Foundation
import UIKit
import SnapKit

protocol OnButtonListener {
    func onButton1( _ val1: String )
     func onButton2( _ val2: String )
}

class MyView: UIView {
var onButtonListener: OnButtonListener?
var val1 = "abc"
var val2 = "123"

override init( frame: CGRect ) {
    super.init( frame: frame )
    let b1 = UIButton()
    let b2 = UIButton() // i'm using snapkit
    b1.addTarget(self, action: #selector(onB1), for: .touchUpInside)
    b2.addTarget(self, action: #selector(onB2), for: .touchUpInside)
}

@objc func onB1() {
    if onButtonListener != nil {
        onButtonListener!.onButton1(val1 )
    }
}

@objc func onB2() {
    if onButtonListener != nil {
        onButtonListener!.onButton2(val2 )
    }
}
}

class MyVC : UIViewController {
   override func viewDidLoad() {
    super.viewDidLoad()
    let myView1 = MyView()
    let myView2 = MyView()

    myView1.onButtonListener = {
        // ???
    }
    myView2.onButtonListener = {
        // ???
    }
}
}

```

I don't know how to implement listener in ViewContorller. I've tried same way as Kotlin but I didn't work too. Thank you for reading.