steipete / Aspects

Delightful, simple library for aspect oriented programming in Objective-C and Swift.

Home Page:https://twitter.com/steipete

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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方法

加上了也无效。。。

commented

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)