In what situation would one use expectationForNotification in swift testing -


i'm little confused what/when expectationfornotification opposed expectationwithdescription. i've been unable find clear examples in swift when , call.

i'm assuming perhaps test notifications looks might more convenient wrapper around whole addobserver() call of notification center.

could give brief explanation of does, when use it, , perhaps few lines of sample code?

thanks

as have imagined expectationfornotification convenience expectation checking if notification raised.

this test:

func testitshouldraiseapassnotificationv1() {     let expectation = expectationwithdescription("notification raised")     let sub = nsnotificationcenter.defaultcenter().addobserverforname("evpassed", object: nil, queue: nil) { (not) -> void in         expectation.fulfill()     }     nsnotificationcenter.defaultcenter().postnotificationname("evpassed", object: nil)     waitforexpectationswithtimeout(0.1, handler: nil)     nsnotificationcenter.defaultcenter().removeobserver(sub) } 

can replaced one:

func testitshouldraiseapassnotificationv2() {     expectationfornotification("evpassed", object: nil, handler: nil)     nsnotificationcenter.defaultcenter().postnotificationname("evpassed", object: nil)     waitforexpectationswithtimeout(0.1, handler: nil) } 

you can find explanation in objc.io number.


Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -