aspect_hook in Swift 3.0
WuKongCoo1 opened this issue · comments
First at all, I am a chineses, my english is terrible. I hope you can unstand what I mean.
I want to hook at postionAfter, but I can't find the option. The source file look like below:
public struct AspectOptions : OptionSet {
public init(rawValue: UInt)
/// Called after the original implementation (default)
public static var positionInstead: AspectOptions { get } /// Will replace the original implementation.
/// Will replace the original implementation.
public static var positionBefore: AspectOptions { get } /// Called before the original implementation.
/// Called before the original implementation.
public static var optionAutomaticRemoval: AspectOptions { get } /// Will remove the hook after the first execution.
}
AspectOptions(rawValue: 0) == postionAfter
Here is my code :
let wrappedBlock:@convention(block) (AspectInfo)-> Void = { aspectInfo in
print("view did load")
}
let wrappedObject: AnyObject = unsafeBitCast(wrappedBlock, to: AnyObject.self)
do {
let option = AspectOptions.init(rawValue: 0)
try UIViewController.aspect_hook(#selector(SuperViewController.viewDidLoad), with: option, usingBlock: wrappedObject)
}catch{
print(error)
}
But this does not have the effect I want. This block aways perform before SuperViewController.viewDidLoad
请使用dynamic修饰你的viewDidLoad
方法
加上了也无效。。。
The default is positionAfter, so you should no need to specify any options, just pass []
like this:
try UIViewController.aspect_hook(#selector(SuperViewController.viewDidLoad), with: [], usingBlock: wrappedObject)