From ab940aacabe4441d686f28db9b15c780eeab0094 Mon Sep 17 00:00:00 2001 From: Amanda Wixted Date: Tue, 7 Jun 2016 20:48:25 -0500 Subject: [PATCH 1/5] Added a test case for returning a double with AspectPositionInstead --- AspectsDemo/AspectsDemoTests/AspectsDemoTests.m | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/AspectsDemo/AspectsDemoTests/AspectsDemoTests.m b/AspectsDemo/AspectsDemoTests/AspectsDemoTests.m index 2bc32fc..2a8b89d 100644 --- a/AspectsDemo/AspectsDemoTests/AspectsDemoTests.m +++ b/AspectsDemo/AspectsDemoTests/AspectsDemoTests.m @@ -307,6 +307,23 @@ - (void)testDoubleReturn { XCTAssertTrue([aspect remove], @"Must be able to deregister"); } +- (void)testDoubleReturnInstead { + TestClass *testClass = [TestClass new]; + double previousExpectedValue = [testClass callReturnsDouble]; + double expectedValue = 3.5; + + id aspect = [testClass aspect_hookSelector:@selector(callReturnsDouble) withOptions:AspectPositionInstead usingBlock:^(id info){ + double toReturn = 3.5; + void *ptr = &toReturn; + [info.originalInvocation setReturnValue:ptr]; + }error:NULL]; + double actualValue = [testClass callReturnsDouble]; + + XCTAssertNotEqual(previousExpectedValue, actualValue, @"Must not return what it returned before we called our Instead"); + XCTAssertEqual(expectedValue, actualValue, @"Must be equal"); + XCTAssertTrue([aspect remove], @"Must be able to deregister"); +} + - (void)testLongLongReturn { TestClass *testClass = [TestClass new]; long long d1 = [testClass callReturnsLongLong]; From ad50111821e9651ab0918469986c547a603e36ca Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 5 Feb 2019 09:07:39 +0000 Subject: [PATCH 2/5] Update readme to warn about production use --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3aa9b59..c585c19 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ A delightful, simple library for aspect oriented programming by [@steipete](http **Think of Aspects as method swizzling on steroids. It allows you to add code to existing methods per class or per instance**, whilst thinking of the insertion point e.g. before/instead/after. Aspects automatically deals with calling super and is easier to use than regular method swizzling. -This is stable and used in hundreds of apps since it's part of [PSPDFKit, an iOS PDF framework that ships with apps like Dropbox or Evernote](http://pspdfkit.com), and now I finally made it open source. +Aspects hooks deep into the class hierarchy and creates dynamic subclasses, much like KVO. There's known issues with this approach, and to this date (February 2019) I do not recommend using Aspects in production. We use it for partial test mocks in, [PSPDFKit, an iOS PDF framework that ships with apps like Dropbox or Evernote](http://pspdfkit.com), it's also very useful for quickly hacking something up. Aspects extends `NSObject` with the following methods: From c3125c5063748c6aa80f18cce54ecc128b51ba8f Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 5 Feb 2019 10:02:57 +0000 Subject: [PATCH 3/5] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c585c19..43e9439 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,9 @@ A delightful, simple library for aspect oriented programming by [@steipete](http **Think of Aspects as method swizzling on steroids. It allows you to add code to existing methods per class or per instance**, whilst thinking of the insertion point e.g. before/instead/after. Aspects automatically deals with calling super and is easier to use than regular method swizzling. -Aspects hooks deep into the class hierarchy and creates dynamic subclasses, much like KVO. There's known issues with this approach, and to this date (February 2019) I do not recommend using Aspects in production. We use it for partial test mocks in, [PSPDFKit, an iOS PDF framework that ships with apps like Dropbox or Evernote](http://pspdfkit.com), it's also very useful for quickly hacking something up. +Aspects hooks deep into the class hierarchy and creates dynamic subclasses, much like KVO. There's known issues with this approach, and to this date (February 2019) **I STRICTLY DO NOT RECOMMEND TO USE Aspects IN PRODUCTION CODE**. We use it for partial test mocks in, [PSPDFKit, an iOS PDF framework that ships with apps like Dropbox or Evernote](http://pspdfkit.com), it's also very useful for quickly hacking something up. + +Aspects uses `_objc_msgForward` which causes issues with other code that uses message forwarding. Aspects extends `NSObject` with the following methods: From 48c482fe251aefd98307d239faea6301fa8fe084 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 25 Nov 2025 13:20:45 +0100 Subject: [PATCH 4/5] Add hook emoji to README title --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 43e9439..1af6acb 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -Aspects v1.4.2 [![Build Status](https://travis-ci.org/steipete/Aspects.svg?branch=master)](https://travis-ci.org/steipete/Aspects) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) +Aspects v1.4.2 🪝 [![Build Status](https://travis-ci.org/steipete/Aspects.svg?branch=master)](https://travis-ci.org/steipete/Aspects) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) ============== A delightful, simple library for aspect oriented programming by [@steipete](http://twitter.com/steipete). From 673e51e8ed612431340e0928f44c1ab1cf40d893 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 25 Nov 2025 14:09:11 +0100 Subject: [PATCH 5/5] Normalize header format --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1af6acb..152ba1c 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -Aspects v1.4.2 🪝 [![Build Status](https://travis-ci.org/steipete/Aspects.svg?branch=master)](https://travis-ci.org/steipete/Aspects) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) +Aspects v1.4.2 🪝 - AOP for Objective-C (10k+ stars) [![Build Status](https://travis-ci.org/steipete/Aspects.svg?branch=master)](https://travis-ci.org/steipete/Aspects) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) ============== A delightful, simple library for aspect oriented programming by [@steipete](http://twitter.com/steipete).