-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRx_NSNetServiceBrowser.swift
45 lines (35 loc) · 1.34 KB
/
Rx_NSNetServiceBrowser.swift
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
42
43
44
45
//
// Rx_MDNS.swift
// EdgeRemote
//
// Created by Daniel Poulsen on 09/03/2016.
// Copyright © 2016 cambridgeaudio. All rights reserved.
//
import Foundation
import RxSwift
import RxCocoa
class RxNSNetServiceBrowserDelegateProxy : DelegateProxy
, NSNetServiceBrowserDelegate
, DelegateProxyType {
class func currentDelegateFor(object: AnyObject) -> AnyObject? {
let serviceBrowser: NSNetServiceBrowser = object as! NSNetServiceBrowser
return serviceBrowser.delegate
}
class func setCurrentDelegate(delegate: AnyObject?, toObject object: AnyObject) {
let serviceBrowser: NSNetServiceBrowser = object as! NSNetServiceBrowser
serviceBrowser.delegate = delegate as? NSNetServiceBrowserDelegate
}
}
extension NSNetServiceBrowser{
public var rx_delegate: DelegateProxy {
return proxyForObject(RxNSNetServiceBrowserDelegateProxy.self, self)
}
public var rx_didFindServiceMoreComing: Observable<(service : NSNetService, moreComing : Bool)> {
return rx_delegate.observe(#selector(NSNetServiceBrowserDelegate.netServiceBrowser(_:didFindService:moreComing:)))
.map { a in
let service = a[1] as! NSNetService
let moreComing = a[2]as! Bool
return (service : service, moreComing : moreComing)
}
}
}