Aspects icon indicating copy to clipboard operation
Aspects copied to clipboard

aspect_hook in Swift 3.0

Open WuKongCoo1 opened this issue 6 years ago • 5 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.

}

WuKongCoo1 avatar Aug 08 '17 08:08 WuKongCoo1

AspectOptions(rawValue: 0) == postionAfter

Hyosung avatar Aug 10 '17 01:08 Hyosung

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

WuKongCoo1 avatar Aug 10 '17 01:08 WuKongCoo1

请使用dynamic修饰你的viewDidLoad方法

Hyosung avatar Aug 11 '17 09:08 Hyosung

加上了也无效。。。

WuKongCoo1 avatar Aug 11 '17 10:08 WuKongCoo1

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)

JunyuKuang avatar Sep 07 '17 04:09 JunyuKuang