Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions AspectsDemo/AspectsDemoTests/AspectsDemoTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -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<AspectInfo> 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];
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
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).

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

Expand Down