ios


Observable for selector - RxSwift


I'm trying to migrate my FRP understanding from ReactiveCocoa 2.5 to RxSwift and I have one misunderstanding. In ReactiveCocoa, I used rac_signalForSelector when I wanted to observe an invocation of a method. Is there any way to implement this logic using RxSwift?
I wrote a small example in which I want to dispose a subscription when the test method invokes. But in the subscribe block I can still see a next(6) event. What am I doing wrong?
let subject = PublishSubject<Int>()
subject.takeUntil(self.rx.sentMessage(#selector(test))).subscribe { event in
print(event)
}
subject.onNext(3)
test()
subject.onNext(6)
//////////////////
func test() {
}
You can use sentMessage:
class ViewController: UIViewController {
let disposeBag = DisposeBag()
override func viewDidLoad() {
super.viewDidLoad()
self.rx.sentMessage(#selector(UIViewController.viewWillAppear(_:)))
.subscribe({ e in
print(e)
})
.addDisposableTo(disposeBag)
}
}
Outputs:
next([0])
Or another example:
class SomeNSObjectClass: NSObject {
}
class ViewController: UIViewController {
let disposeBag = DisposeBag()
override func viewDidLoad() {
super.viewDidLoad()
let myObj = SomeNSObjectClass()
myObjc.rx.sentMessage(NSSelectorFromString("dealloc"))
.subscribe({ e in
print(e)
})
.addDisposableTo(disposeBag)
}
}
}
Outputs:
next([])
completed

Related Links

Regex capture group swift
Scroll Percentage of Cell with offset
Universal layout constraints
any workaround for an Apps using the FB to access an Apps user's friend's friends profile photo and name
App not stopped when launched for background fetch from Xcode
Accelerometer works in first game, but goes crazy in the second
Integration OpenAM - OAuth2 with iOS
How to set Background image to AVMutableVideoCompositionInstruction
assign in NON-ARC and retain cycle
Where can I view my PFUser objects in the Parse Data Browser?
Insert multiple row data same time sqlite with json ios
xmppframework: “Undefined symbols for architecture x86_64”
completion handler error in dispatch_async - optional unwrapping
UITableViewController Changes Size When View Tab Changes - Swift iOS
Split a string into letters [duplicate]
iOS: Large UIAlertController ActionSheet bouncing while scrolling and not showing line separators

Categories

HOME
ssl
dom
coffeescript
xaml
runnable
varnish
servlets
middleware
android-bluetooth
zipfile
tcplistener
identifier
eloqua
html5-video
deserialization
monaco-editor
records
hp-alm
media-source
jmeter-plugins
dotnetbar
opencms
eonasdan-datetimepicker
slf4j
toolbar
rrd
webfocus
kube-dns
complex-networks
dashboard-designer
querydsl
pdfstamper
nio
disqus
flags
essbase
karnaugh-map
keyboard-maestro
appdynamics
strip-tags
openwebanalytics
name-mangling
playback
python-module
mysql-error-1050
mapr
configuration-profile
evaluate
measurement-protocol
business-logic
printscreen
webpagetest
ng-annotate
sql-server-2016-express
cover
rabbitvcs
jquery-load
win32com
pypdf
wchar-t
user-registration
treegrid
maven-cargo
dhc
solr-boost
omap
ehcache-bigmemory
newsql
ratingbar
textselection
wmv
lightstreamer
notifyicon
cfile
inputview
colormatrix
showcaseview
sysadmin
mips64
rte
hla
google-chrome-frame
python-dateutil
source-highlighting
double-precision
alternate-data-stream
gigaspaces
libavg
documentviewer
letter-spacing
ssao
eye-detection
noaa
iphone-sdk-3.1
run-length-encoding
web-based
shareware
mud

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App