forked from swiftwasm/JavaScriptKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProtocol.swift
More file actions
41 lines (32 loc) · 982 Bytes
/
Protocol.swift
File metadata and controls
41 lines (32 loc) · 982 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import JavaScriptKit
@JS protocol MyViewControllerDelegate {
func onSomethingHappened()
func onValueChanged(_ value: String)
func onCountUpdated(count: Int) -> Bool
func onLabelUpdated(_ prefix: String, _ suffix: String)
func isCountEven() -> Bool
}
@JS class MyViewController {
@JS
var delegate: MyViewControllerDelegate
@JS
var secondDelegate: MyViewControllerDelegate?
@JS init(delegate: MyViewControllerDelegate) {
self.delegate = delegate
}
@JS func triggerEvent() {
delegate.onSomethingHappened()
}
@JS func updateValue(_ value: String) {
delegate.onValueChanged(value)
}
@JS func updateCount(_ count: Int) -> Bool {
return delegate.onCountUpdated(count: count)
}
@JS func updateLabel(_ prefix: String, _ suffix: String) {
delegate.onLabelUpdated(prefix, suffix)
}
@JS func checkEvenCount() -> Bool {
return delegate.isCountEven()
}
}