ios - Add a type function to a Swift unit test target -


how 1 go making type function (defined in extension) visible test target in swift? if have following extension in project:

extension nsdata {     class func xor(inputdata: nsdata, withkey key: nsdata) -> nsdata {                     ...                     return nsdata(bytes: output.baseaddress, length: inputdata.length)     } } 

the xor function visible the main project not in test target. have @testable import mymodule in test file. (as aside, interestingly variables added in extension visible test target).

there 3 ways (that can recall) of making function visible within test target.

  1. add test target target membership of file containing extension.
  2. promote function internal (which implicitly set omitting access modifier) public.
  3. upgrade xcode 7 beta , use swift 2's new @testable attribute import module. doing implicitly promote internal variables/methods/etc public make them visible within tests target.
@testable import mymodule 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -