Aspects icon indicating copy to clipboard operation
Aspects copied to clipboard

Use of undeclared type 'AspectInfo' in Swift

Open orange2003 opened this issue 9 years ago • 1 comments

in swift 2.1 this code is good let b: (aspectInfo:AnyObject)->() = {aspectInfo in let vc:UIViewController = aspectInfo.instance() as! UIViewController; let backItem:UIBarButtonItem = UIBarButtonItem(title:"", style: .Plain, target: nil, action: nil); vc.navigationItem.backBarButtonItem = backItem; }

but in Xcode 7.3 swift 2.2 is error Value of type 'AnyObject' has no member 'instance' why?? I have change code to let b: (aspectInfo:AspectInfo)->() = {aspectInfo in let vc:UIViewController = aspectInfo.instance() as! UIViewController; let backItem:UIBarButtonItem = UIBarButtonItem(title:"", style: .Plain, target: nil, action: nil); vc.navigationItem.backBarButtonItem = backItem; } get error Use of undeclared type 'AspectInfo'
Help me about it

orange2003 avatar Mar 28 '16 02:03 orange2003

    let block: @convention(block) (AnyObject!) -> Void = {
        info in
        let aspectInfo = info as! AspectInfo
        let controller =  aspectInfo.instance()
        print("\(controller) deinit")
    }
    let blobj: AnyObject = unsafeBitCast(block, AnyObject.self)
    do {
        let originalSelector = NSSelectorFromString("dealloc")
        try UIViewController.aspect_hookSelector(originalSelector, withOptions: .PositionBefore, usingBlock: blobj)
    } catch  {
        print("error = \(error)")
    }

This can be solved...

codwam avatar Apr 03 '16 14:04 codwam