Skip to content

Instantly share code, notes, and snippets.

@OctoberHammer
Created June 13, 2017 16:56
Show Gist options
  • Save OctoberHammer/67784c48a7ba18cd309c2a0c9c4f5382 to your computer and use it in GitHub Desktop.
Save OctoberHammer/67784c48a7ba18cd309c2a0c9c4f5382 to your computer and use it in GitHub Desktop.
callBack
import UIKit
import Foundation
class ConnectBLE {
var callBackFunc: ()->()
init(callFunc: @escaping () -> ()){
callBackFunc = callFunc
}
}
let inst = ConnectBLE(callFunc: {print("Hello world")})
inst.callBackFunc()
let inst1 = ConnectBLE {print("Hello Another world")}
inst1.callBackFunc()
@wer14
Copy link

wer14 commented Jun 13, 2017

спасибо, сейчас попробую

@OctoberHammer
Copy link
Author

Ща

@wer14
Copy link

wer14 commented Jun 13, 2017

Нет, не работает.  Error: use of unresolved indentifier self.

@OctoberHammer
Copy link
Author

да, сек,

@OctoberHammer
Copy link
Author

class ConnectBLE {
var callBackFunc: ()->()
init(callFunc: @escaping () -> ()){

	callBackFunc = callFunc
}

func runCallBackFunc() {
	callBackFunc()
}

}

class DelegateARC {

static func RaspakHC05() -> () {
	print("awesome")
}

let object = ConnectBLE(callFunc: {DelegateARC.RaspakHC05()})

}

let myInst = DelegateARC()

myInst.object.runCallBackFunc()

======

Пришлось
а) пометить RaspakHC05 как статик, иначе не компилось, ви в общем понятно почему
б) убрать у object приват, иначе никак не проверить работоспособность

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment