Aspect is a lightweight, pure-Swift library for for aspect oriented programming. This project is heavily inspired by the popular Aspects. It provides you a chance to use a pure-Swift alternative in your next app.
- Hook object selector
- Hook different classes selector in the same hierarchy
- Hook class and static selector
- Provide more friendly Swift interfaces
public class Test: NSObject {
@objc dynamic func test(id: Int, name: String) {
}
@objc dynamic static func classSelector(id: Int, name: String) {
}
}
let test = Test()
let wrappedBlock: @convention(block) (AspectInfo, Int, String) -> Void = { aspectInfo, id, name in
}
let block: AnyObject = unsafeBitCast(wrappedBlock, to: AnyObject.self)
test.hook(selector: #selector(Test.test(id:name:)), strategy: .before, block: )
let test = Test()
_ = try? test.hook(selector: #selector(Test.test(id:name:)), strategy: .before) { (_, id: Int, name: String) in
}
_ = try? Test.hook(selector: #selector(Test.test(id:name:)), strategy: .before) { (_, id: Int, name: String) in
}
_ = try? Test.hook(selector: #selector(Test.classSelector(id:name:)), strategy: .before) { (_, id: Int, name: String) in
}
- iOS 8.0+
- Swift 4.0-5.x
- Support remove aspect
- Improve detail
- Support Cocopods install
Add the following line to your Cartfile
git "https://github.com/woshiccm/Aspect.git" "master"
Aspect is released under the MIT license. See LICENSE for details.