GithubHelp home page GithubHelp logo

imooccodejesse / aspectop Goto Github PK

View Code? Open in Web Editor NEW

This project forked from woshiccm/aspect

0.0 0.0 0.0 35 KB

A lightweight, pure-Swift library for aspect oriented programming

License: MIT License

Objective-C 1.91% Swift 98.09%

aspectop's Introduction

Carthage compatible badge-pms Swift Version

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

  • Hook object selector
  • Hook different classes selector in the same hierarchy
  • Hook class and static selector
  • Provide more friendly Swift interfaces

Usage

Hook object selector with OC block

public class Test: NSObject {

    @objc dynamic func test(id: Int, name: String) {

    }

    @objc dynamic static func classSelector(id: Int, name: String) {

    }
}

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

let test = Test()

_ = try? test.hook(selector: #selector(Test.test(id:name:)), strategy: .before) { (_, id: Int, name: String) in

}

Hook class instance selector with Swift block

_ = try? Test.hook(selector: #selector(Test.test(id:name:)), strategy: .before) { (_, id: Int, name: String) in

}

Hook class class and static selector with Swift block


_ = try? Test.hook(selector: #selector(Test.classSelector(id:name:)), strategy: .before) { (_, id: Int, name: String) in

}

Requirements

  • iOS 8.0+
  • Swift 4.0-5.x

Next Steps

  • Support remove aspect
  • 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.

aspectop's People

Contributors

woshiccm avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.