chorim / 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 Swift Package Manager 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 5, 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

It is also available through Swift Package Manager:

.package(url: "https://github.com/chorim/SwiftyInvocation.git", branch: "master")

Author

Piotr Tobolski, piotr.tobolski@me.com

Insu Byeon, me@byeon.is

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:Swift 55.7%Language:Objective-C 38.8%Language:Ruby 5.5%