Swift collections in unit tests -



Swift collections in unit tests -

i new swift , don't understand implicit type casting, have in unit test:

let protocols: anyobject? = nsbundle.mainbundle().infodictionary?["uisupportedexternalaccessoryprotocols"];

i need test protocols exists, array , contains "foo" , "bar".

i came solution:

let protocols: anyobject? = nsbundle.mainbundle().infodictionary?["uisupportedexternalaccessoryprotocols"]; if allow p = protocols as? [string] { xctasserttrue(contains(p, "foo")); xctasserttrue(contains(p, "bar")); } else { xctfail("uisupportedexternalaccessoryprotocols must array"); }

is there improve way handle it?

unit-testing swift

Comments

Popular posts from this blog

c - Compilation of a code: unkown type name string -

java - Bypassing "final local variable defined in an enclosing type" -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -