piotrtobolski / SwiftyInvocation

NSInvocation for Swift + helpers

Home Page:https://piotrtobolski.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SwiftyInvocation

CI Status CocoaPods compatible Carthage compatible Twitter Version License Platform

Have you ever dreamed about using NSInvocation from Swift code? You hate Apple for the NS_SWIFT_UNAVAILABLE macro?

Me neither.

But sometimes we just HAVE to use it. And here it is.

Example

Check the unit tests.

let array: NSArray = ["1", "2", "3"]

let selector = #selector(NSArray.object(at:))
let methodSignature = NSArray.si_instanceMethodSignature(for: selector)
let invocation = SIInvocation(methodSignature: methodSignature)
invocation.target = array
invocation.selector = selector
var argument = 1
invocation.setArgument(&argument, at: 2)
invocation.retainArguments()

invocation.invoke()

var returnValue: Unmanaged<NSString>?
invocation.getReturnValue(&returnValue)

XCTAssertEqual(returnValue?.takeUnretainedValue(), "2")

Requirements

Swift 3, Objective-C runtime

Installation

SwiftyInvocation is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "SwiftyInvocation"

It is also available through Carthage:

github "piotr-tobolski/SwiftyInvocation" ~> 0.1.0

Author

Piotr Tobolski, piotr.tobolski@me.com

License

SwiftyInvocation is available under the MIT license. See the LICENSE file for more info.

About

NSInvocation for Swift + helpers

https://piotrtobolski.com

License:MIT License


Languages

Language:Shell 40.2%Language:Objective-C 33.1%Language:Swift 22.0%Language:Ruby 4.6%