Skip to content

Regenerated the project with the latest from ProjectTemplate #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 27, 2021
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/cocoapods.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ jobs:

- name: Lint (Static Library)
run: |
pod lib lint --use-libraries --skip-tests
pod lib lint --use-libraries
15 changes: 15 additions & 0 deletions .github/workflows/swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: SwiftLint
on: [push, workflow_dispatch]

jobs:
build:
name: Run SwiftLint
runs-on: macOS-latest

steps:
- name: Checkout Code
uses: actions/checkout@v2

- name: Run SwiftLint
run: |
swiftlint lint --reporter github-actions-logging
4 changes: 3 additions & 1 deletion .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ opt_in_rules:
- vertical_parameter_alignment_on_call
- pattern_matching_keywords
- fatal_error_message
- implicit_return
- implicitly_unwrapped_optional
- joined_default_parameter
- let_var_whitespace
Expand Down Expand Up @@ -59,6 +58,9 @@ opt_in_rules:

reporter: "xcode"

function_body_length:
- 60 #warning

identifier_name:
excluded:
- i
13 changes: 8 additions & 5 deletions MethodNotificationCenter.podspec
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
Pod::Spec.new do |s|

s.name = "MethodNotificationCenter"
s.version = "0.1.1"
s.version = "0.1.2"
s.summary = "Simple Objective-C Runtime Injection"
s.description = <<-DESC
A lightweight framework enabling easy snooping on Objective-C methods for iOS, macOS, and tvOS.
DESC

s.homepage = "https://github.com/SomeRandomiOSDev/MethodNotificationCenter"
s.license = "MIT"
s.author = { "Joseph Newton" => "somerandomiosdev@gmail.com" }
s.author = { "Joe Newton" => "somerandomiosdev@gmail.com" }
s.source = { :git => "https://github.com/SomeRandomiOSDev/MethodNotificationCenter.git", :tag => s.version.to_s }

s.ios.deployment_target = '9.0'
s.macos.deployment_target = '10.10'
s.tvos.deployment_target = '9.0'
s.watchos.deployment_target = '2.0'

s.source = { :git => "https://github.com/SomeRandomiOSDev/MethodNotificationCenter.git", :tag => s.version.to_s }
s.source_files = 'Sources/**/*.{h,m,s}'
s.source_files = 'Sources/MethodNotificationCenter/**/*.{h,m,s}'
s.module_map = 'Sources/MethodNotificationCenter/module/module.modulemap'
s.swift_versions = ['4.0', '4.2', '5.0']
s.cocoapods_version = '>= 1.7.3'

Expand All @@ -27,7 +28,9 @@ Pod::Spec.new do |s|
ts.tvos.deployment_target = '9.0'
ts.watchos.deployment_target = '2.0'

ts.source_files = 'Tests/**/*.{m,swift}'
ts.pod_target_xcconfig = { 'SWIFT_INCLUDE_PATHS' => '$PODS_TARGET_SRCROOT/Sources/MethodNotificationCenter/include',
'HEADER_SEARCH_PATHS' => '$PODS_TARGET_SRCROOT/Sources/MethodNotificationCenter/include' }
ts.source_files = 'Tests/**/*.{m,swift}'
end

end
404 changes: 202 additions & 202 deletions MethodNotificationCenter.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ let package = Package(

targets: [
.target(name: "MethodNotificationCenter"),

.testTarget(name: "MethodNotificationCenterObjCTests", dependencies: ["MethodNotificationCenter"]),
.testTarget(name: "MethodNotificationCenterSwiftTests", dependencies: ["MethodNotificationCenter"])
]
],

swiftLanguageVersions: [.version("5")]
)
20 changes: 7 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
MethodNotificationCenter
========
# MethodNotificationCenter
Objective-C Runtime Injection

[![Codacy Badge](https://api.codacy.com/project/badge/Grade/d30d31c29f17449481b97a04610ff5b9)](https://app.codacy.com/app/SomeRandomiOSDev/MethodNotificationCenter?utm_source=github.com&utm_medium=referral&utm_content=SomeRandomiOSDev/MethodNotificationCenter&utm_campaign=Badge_Grade_Dashboard)
Expand All @@ -25,8 +24,7 @@ This library allows one to be notified, in a fashion very similar to Foundation'

It should be noted that this library is for _educational purposes_ only. The way in which this library operates not only makes it volatile and unsuitable to production releases, but use of it would likely not pass Apple's App Store review (untested).

Installation
--------
## Installation

**MethodNotificationCenter** is available through [CocoaPods](https://cocoapods.org), [Carthage](https://github.com/Carthage/Carthage) and the [Swift Package Manager](https://swift.org/package-manager/).

Expand All @@ -45,11 +43,10 @@ github "SomeRandomiOSDev/MethodNotificationCenter"
To install via the Swift Package Manager add the following line to your `Package.swift` file's `dependencies`:

```swift
.package(url: "https://github.com/SomeRandomiOSDev/MethodNotificationCenter.git", from: "0.1.1")
.package(url: "https://github.com/SomeRandomiOSDev/MethodNotificationCenter.git", from: "0.1.0")
```

Usage
--------
## Usage

First import **MethodNotificationCenter** at the top of your source file:

Expand Down Expand Up @@ -109,17 +106,14 @@ There are some notable limitations to the capabilities of this library:
* Method notifications aren't sent recursively. That is, you'll receive a notification for the "top-level" call of the given method, but if the method (or any of its internal method calls) calls the same method a notification will _not_ be sent for that.
* Due to optimizations made by the Swift compiler, Swift calls to methods written in Swift (but annotated with the `@objc` attribute) are usually hard-coded by the compiler and don't use the Objective-C runtime, which prevent notifications from being sent. Classes written in Objective-C and called from Swift (or vice-versa) shouldn't have this issue. See `Tests/MethodNotificationCenterTests/MethodNotificationCenterSwiftTests/MethodNotificationCenterTests.swift` for examples.

Contributing
--------
## Contributing

If you have need for a specific feature or you encounter a bug, please open an issue. If you extend the functionality of **MethodNotificationCenter** yourself or you feel like fixing a bug yourself, please submit a pull request.

Author
--------
## Author

Joe Newton, somerandomiosdev@gmail.com

License
--------
## License

**MethodNotificationCenter** is available under the MIT license. See the `LICENSE` file for more info.
2 changes: 1 addition & 1 deletion Sources/MethodNotificationCenter/module/module.modulemap
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
framework module MethodNotificationCenter {
header "MethodNotification.h"
header "MethodNotificationCenter.h"
header "MethodNotificationObservable.h"
header "MethodNotification.h"
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// MethodNotificationCenterTests.m
// MethodNotificationCenterObjCTests.m
// MethodNotificationCenterTests
//
// Copyright © 2021 SomeRandomiOSDev. All rights reserved.
Expand All @@ -17,18 +17,18 @@ - (void)incrementBy2;
- (void)noop;
@end

// MARK: - MethodNotificationCenterTests Interface
// MARK: - MethodNotificationCenterObjCTests Interface

@interface MethodNotificationCenterTests : XCTestCase
@interface MethodNotificationCenterObjCTests : XCTestCase
@end

// MARK: - MethodNotificationCenterTests Implementation
// MARK: - MethodNotificationCenterObjCTests Implementation

@implementation MethodNotificationCenterTests
@implementation MethodNotificationCenterObjCTests

// MARK: Test Methods

- (void)testRecivingNotifications {
- (void)testReceivingNotifications {
TestClass1 *test = [[TestClass1 alloc] init];

id observer = [MethodNotificationCenter addObserverForSelector:@selector(increment) object:test callback:^(MethodNotification *notification) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// MethodNotificationCenterTests.swift
// MethodNotificationCenterSwiftTests.swift
// MethodNotificationCenterTests
//
// Copyright © 2021 SomeRandomiOSDev. All rights reserved.
Expand All @@ -8,13 +8,13 @@
import MethodNotificationCenter
import XCTest

// MARK: - MethodNotificationCenterTests Definition
// MARK: - MethodNotificationCenterSwiftTests Definition

class MethodNotificationCenterTests: XCTestCase {
class MethodNotificationCenterSwiftTests: XCTestCase {

// MARK: Test Methods

func testRecivingNotifications1() {
func testReceivingNotifications1() {
let test = TestClass1()
let observer = MethodNotificationCenter.addObserver(for: #selector(TestClass1.increment), object: test) { notification in
XCTAssertEqual(test.value, (notification.isPriorToMethodCall ? 0 : 2))
Expand All @@ -23,13 +23,13 @@ class MethodNotificationCenterTests: XCTestCase {

XCTAssertEqual(test.value, 0)
test.perform(#selector(TestClass1.increment))
//test.increment() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
// test.increment() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
XCTAssertEqual(test.value, 3)

MethodNotificationCenter.removeObserver(observer)
}

func testRecivingNotifications2() {
func testReceivingNotifications2() {
let test = TestClass2()
let observer = MethodNotificationCenter.addObserver(for: #selector(TestClass1.increment), object: test) { notification in
XCTAssertEqual(test.value, (notification.isPriorToMethodCall ? 0 : 2))
Expand All @@ -38,13 +38,13 @@ class MethodNotificationCenterTests: XCTestCase {

XCTAssertEqual(test.value, 0)
test.perform(#selector(TestClass1.increment))
//test.increment() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
// test.increment() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
XCTAssertEqual(test.value, 3)

MethodNotificationCenter.removeObserver(observer)
}

func testRecivingNotifications3() {
func testReceivingNotifications3() {
let test = TestClass3()
let observer = MethodNotificationCenter.addObserver(for: #selector(TestClass1.increment), object: test) { notification in
XCTAssertEqual(test.value, (notification.isPriorToMethodCall ? 0 : 2))
Expand All @@ -53,7 +53,7 @@ class MethodNotificationCenterTests: XCTestCase {

XCTAssertEqual(test.value, 0)
test.perform(#selector(TestClass1.increment))
//test.increment() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
// test.increment() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
XCTAssertEqual(test.value, 3)

MethodNotificationCenter.removeObserver(observer)
Expand All @@ -76,8 +76,8 @@ class MethodNotificationCenterTests: XCTestCase {
XCTAssertEqual(test2.value, 0)
test.perform(#selector(TestClass1.increment))
test2.perform(#selector(TestClass1.increment))
//test.increment() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
//test2.increment() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
// test.increment() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
// test2.increment() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
XCTAssertEqual(test.value, 3)
XCTAssertEqual(test2.value, 3)

Expand All @@ -99,18 +99,18 @@ class MethodNotificationCenterTests: XCTestCase {

XCTAssertEqual(test.value, 0)
test.perform(#selector(TestClass1.increment))
//test.increment() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
// test.increment() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
XCTAssertEqual(test.value, 3)
test.perform(#selector(TestClass1.incrementBy2))
//test.incrementBy2() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
// test.incrementBy2() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
XCTAssertEqual(test.value, 7)
MethodNotificationCenter.removeObserver(observer2)
test.perform(#selector(TestClass1.incrementBy2))
//test.incrementBy2() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
// test.incrementBy2() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
XCTAssertEqual(test.value, 9)
MethodNotificationCenter.removeObserver(observer)
test.perform(#selector(TestClass1.increment))
//test.increment() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
// test.increment() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
XCTAssertEqual(test.value, 10)
}

Expand Down Expand Up @@ -139,30 +139,30 @@ class MethodNotificationCenterTests: XCTestCase {
XCTAssertEqual(test2.value, 0)
test.perform(#selector(TestClass1.increment))
test2.perform(#selector(TestClass1.increment))
//test.increment() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
//test2.increment() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
// test.increment() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
// test2.increment() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
XCTAssertEqual(test.value, 3)
XCTAssertEqual(test2.value, 3)
test.perform(#selector(TestClass1.incrementBy2))
test2.perform(#selector(TestClass1.incrementBy2))
//test.incrementBy2() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
//test2.incrementBy2() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
// test.incrementBy2() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
// test2.incrementBy2() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
XCTAssertEqual(test.value, 7)
XCTAssertEqual(test2.value, 7)
MethodNotificationCenter.removeObserver(observer2)
MethodNotificationCenter.removeObserver(observer4)
test.perform(#selector(TestClass1.incrementBy2))
test2.perform(#selector(TestClass1.incrementBy2))
//test.incrementBy2() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
//test2.incrementBy2() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
// test.incrementBy2() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
// test2.incrementBy2() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
XCTAssertEqual(test.value, 9)
XCTAssertEqual(test2.value, 9)
MethodNotificationCenter.removeObserver(observer)
MethodNotificationCenter.removeObserver(observer3)
test.perform(#selector(TestClass1.increment))
test2.perform(#selector(TestClass1.increment))
//test.increment() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
//test2.increment() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
// test.increment() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
// test2.increment() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
XCTAssertEqual(test.value, 10)
XCTAssertEqual(test2.value, 10)
}
Expand All @@ -189,7 +189,7 @@ class MethodNotificationCenterTests: XCTestCase {

XCTAssertEqual(test.value, 0)
test.perform(#selector(TestClass1.noop))
//test.noop() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
// test.noop() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
XCTAssertEqual(test.value, 8)

MethodNotificationCenter.removeObserver(observer)
Expand All @@ -208,11 +208,11 @@ class MethodNotificationCenterTests: XCTestCase {

XCTAssertEqual(test.value, 0)
test.perform(#selector(TestClass1.increment))
//test.increment() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
// test.increment() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
XCTAssertEqual(test.value, 3)
unmanagedObserver.release() // causes observer to be overreleased, but that's okay for our unit testing
test.perform(#selector(TestClass1.increment))
//test.increment() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
// test.increment() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
XCTAssertEqual(test.value, 4)
}
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/carthage.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash

#
# Needed to circumvent an issue with Carthage version < 0.37.0: https://github.com/Carthage/Carthage/issues/3019
#
# carthage.sh
Expand Down
2 changes: 1 addition & 1 deletion scripts/resolvepath.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash

#
# resolvepath.sh
# Usage example: ./resolvepath.sh "./some/random/path/../../"

Expand Down
Loading