Mockingbird Documentation 0.18.0

Function any(_:​)

public func any<T: NSObjectProtocol>(_ type: T.Type = T.self) -> T  

Matches all Objective-C object argument values.

Argument matching allows you to stub or verify specific invocations of parameterized methods. Use the wildcard argument matcher any as a type safe placeholder for matching any argument value.

// Protocol referencing Obj-C object types
protocol Bird {
  func canChirp(volume: NSNumber) -> Bool
}

given(bird.canChirp(volume: any())).willReturn(true)
print(bird.canChirp(volume: 10))  // Prints "true"
verify(bird.canChirp(volume: any())).wasCalled()

Methods overloaded by parameter type can be disambiguated by explicitly specifying the type.

// Protocol referencing Obj-C object types
protocol Bird {
  func send<T: NSObject>(_ message: T)  // Overloaded generically
  func send(_ message: NSString)        // Overloaded explicitly
  func send(_ message: NSData)
}

given(bird.send(any(NSString.self))).will { print($0) }

bird.send("Hello")  // Prints "Hello"

verify(bird.send(any(NSString.self))).wasCalled()
verify(bird.send(any(NSData.self))).wasNeverCalled()

Parameters

type T.​Type

The parameter type used to disambiguate overloaded methods.