How to reference Swift Playground itself?

前端 未结 3 1474
一整个雨季
一整个雨季 2020-12-09 19:40

from How to create a button programmatically?

self doesn\'t work in swift playground :

button.addTarget(self, action: \"buttonAction:\", forControlE         


        
3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-09 20:14

    I do this successfully with Cocoa.

    Make your class a subclass of NSObject. Create an NSWindow in your class and move the button and the action into your class. Then you can set the button's target to self.

    Try it with UIKit and let us know if it works.

提交回复
热议问题