Aspect -- 纯Swift写的AOP库

作者: 小凉介 | 来源:发表于2019-06-04 22:26 被阅读269次

主要难点是Swift中拿到Selector以及Block的NSInvocation和NSMethodSignature, 感兴趣的可以看看。

地址:https://github.com/woshiccm/Aspect

aspect.png

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.

Features

  • [x] Hook object selector
  • [x] Provide a more friendly Swift interface

Usage

Hook object selector with OC block

public class Test: NSObject {
   @objc dynamic func test(id: Int, name: String) {
        print(id)
        print(name)
    }
}

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: )

Hook object selector with Swift block

test.hook(selector: #selector(Test.test(id:name:)), strategy: .before) { (aspectInfo: AspectInfo, id: Int, name: String) in

}

Requirements

  • iOS 8.0+
  • Swift 4.0-5.x

Next Steps

  • Support hook class selector
  • Improve detail
  • Support Cocopods install

Installation

Carthage

Add the following line to your Cartfile

git "https://github.com/woshiccm/Aspect.git" "master"

Contributors

Backers

License

Aspect is released under the MIT license. See LICENSE for details.

相关文章

  • Aspect -- 纯Swift写的AOP库

    主要难点是Swift中拿到Selector以及Block的NSInvocation和NSMethodSignatu...

  • AOP

    AOP 基本概念 OOP是自上而下从controller-service-dao-数据库。 AOP(Aspect-...

  • Spring学习 一 AOP

    什么是AOP? 面向切面编程 (AOP是Aspect Oriented Program的字母首写)。 意为:在程序...

  • AOP总结

    ## AOP简介 ###1.1 什么是AOP AOP,Aspect Oriented Programming 面向...

  • spring-aop基础学习

    Spring AOP基础 AOP 1.什么是AOP AOP(Aspect Oriented Programming...

  • Java实训(3) -- Spring核心之AOP -- 201

    Spring AOP编程 什么是 AOP 编程? AOP是Aspect Oriented Programming的...

  • AOP

    1:AOP 简介 AOP: Aspect Oriented Programming 面向切面...

  • AOP概述-术语

    AOP概念-术语 什么是AOP AOP Aspect Oriented Programing 面向切面编程 AOP...

  • Spring AOP

    探秘Spring AOP 使用AOP的好处 AOP(Aspect-Orientid Programming)面向切...

  • Spring Boot之AOP

    一、AOP简介(摘抄) aop 全称 Aspect Oriented Programming ,面向切面,AOP主...

网友评论

    本文标题:Aspect -- 纯Swift写的AOP库

    本文链接:https://www.haomeiwen.com/subject/mhldxctx.html