Skip to content

Commit 1aaeb13

Browse files
Merge pull request #2 from SomeRandomiOSDev/Modernize
Regenerated the project with the latest from ProjectTemplate
2 parents 7d0be6e + efbd722 commit 1aaeb13

21 files changed

+660
-259
lines changed

.github/workflows/cocoapods.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ jobs:
2020
2121
- name: Lint (Static Library)
2222
run: |
23-
pod lib lint --use-libraries --skip-tests
23+
pod lib lint --use-libraries

.github/workflows/swiftlint.yml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: SwiftLint
2+
on: [push, workflow_dispatch]
3+
4+
jobs:
5+
build:
6+
name: Run SwiftLint
7+
runs-on: macOS-latest
8+
9+
steps:
10+
- name: Checkout Code
11+
uses: actions/checkout@v2
12+
13+
- name: Run SwiftLint
14+
run: |
15+
swiftlint lint --reporter github-actions-logging

.swiftlint.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ opt_in_rules:
2929
- vertical_parameter_alignment_on_call
3030
- pattern_matching_keywords
3131
- fatal_error_message
32-
- implicit_return
3332
- implicitly_unwrapped_optional
3433
- joined_default_parameter
3534
- let_var_whitespace
@@ -59,6 +58,9 @@ opt_in_rules:
5958

6059
reporter: "xcode"
6160

61+
function_body_length:
62+
- 60 #warning
63+
6264
identifier_name:
6365
excluded:
6466
- i

MethodNotificationCenter.podspec

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
Pod::Spec.new do |s|
22

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

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

1415
s.ios.deployment_target = '9.0'
1516
s.macos.deployment_target = '10.10'
1617
s.tvos.deployment_target = '9.0'
1718
s.watchos.deployment_target = '2.0'
1819

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

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

30-
ts.source_files = 'Tests/**/*.{m,swift}'
31+
ts.pod_target_xcconfig = { 'SWIFT_INCLUDE_PATHS' => '$PODS_TARGET_SRCROOT/Sources/MethodNotificationCenter/include',
32+
'HEADER_SEARCH_PATHS' => '$PODS_TARGET_SRCROOT/Sources/MethodNotificationCenter/include' }
33+
ts.source_files = 'Tests/**/*.{m,swift}'
3134
end
3235

3336
end

MethodNotificationCenter.xcodeproj/project.pbxproj

+202-202
Large diffs are not rendered by default.

Package.swift

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ let package = Package(
1717

1818
targets: [
1919
.target(name: "MethodNotificationCenter"),
20+
2021
.testTarget(name: "MethodNotificationCenterObjCTests", dependencies: ["MethodNotificationCenter"]),
2122
.testTarget(name: "MethodNotificationCenterSwiftTests", dependencies: ["MethodNotificationCenter"])
22-
]
23+
],
24+
25+
swiftLanguageVersions: [.version("5")]
2326
)

README.md

+7-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
MethodNotificationCenter
2-
========
1+
# MethodNotificationCenter
32
Objective-C Runtime Injection
43

54
[![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)
@@ -25,8 +24,7 @@ This library allows one to be notified, in a fashion very similar to Foundation'
2524

2625
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).
2726

28-
Installation
29-
--------
27+
## Installation
3028

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

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

4745
```swift
48-
.package(url: "https://github.com/SomeRandomiOSDev/MethodNotificationCenter.git", from: "0.1.1")
46+
.package(url: "https://github.com/SomeRandomiOSDev/MethodNotificationCenter.git", from: "0.1.0")
4947
```
5048

51-
Usage
52-
--------
49+
## Usage
5350

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

@@ -109,17 +106,14 @@ There are some notable limitations to the capabilities of this library:
109106
* 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.
110107
* 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.
111108

112-
Contributing
113-
--------
109+
## Contributing
114110

115111
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.
116112

117-
Author
118-
--------
113+
## Author
119114

120115
Joe Newton, somerandomiosdev@gmail.com
121116

122-
License
123-
--------
117+
## License
124118

125119
**MethodNotificationCenter** is available under the MIT license. See the `LICENSE` file for more info.
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
framework module MethodNotificationCenter {
2+
header "MethodNotification.h"
23
header "MethodNotificationCenter.h"
34
header "MethodNotificationObservable.h"
4-
header "MethodNotification.h"
55
}

Tests/MethodNotificationCenterObjCTests/MethodNotificationCenterTests.m renamed to Tests/MethodNotificationCenterObjCTests/MethodNotificationCenterObjCTests.m

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// MethodNotificationCenterTests.m
2+
// MethodNotificationCenterObjCTests.m
33
// MethodNotificationCenterTests
44
//
55
// Copyright © 2021 SomeRandomiOSDev. All rights reserved.
@@ -17,18 +17,18 @@ - (void)incrementBy2;
1717
- (void)noop;
1818
@end
1919

20-
// MARK: - MethodNotificationCenterTests Interface
20+
// MARK: - MethodNotificationCenterObjCTests Interface
2121

22-
@interface MethodNotificationCenterTests : XCTestCase
22+
@interface MethodNotificationCenterObjCTests : XCTestCase
2323
@end
2424

25-
// MARK: - MethodNotificationCenterTests Implementation
25+
// MARK: - MethodNotificationCenterObjCTests Implementation
2626

27-
@implementation MethodNotificationCenterTests
27+
@implementation MethodNotificationCenterObjCTests
2828

2929
// MARK: Test Methods
3030

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

3434
id observer = [MethodNotificationCenter addObserverForSelector:@selector(increment) object:test callback:^(MethodNotification *notification) {

Tests/MethodNotificationCenterSwiftTests/MethodNotificationCenterTests.swift renamed to Tests/MethodNotificationCenterSwiftTests/MethodNotificationCenterSwiftTests.swift

+26-26
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// MethodNotificationCenterTests.swift
2+
// MethodNotificationCenterSwiftTests.swift
33
// MethodNotificationCenterTests
44
//
55
// Copyright © 2021 SomeRandomiOSDev. All rights reserved.
@@ -8,13 +8,13 @@
88
import MethodNotificationCenter
99
import XCTest
1010

11-
// MARK: - MethodNotificationCenterTests Definition
11+
// MARK: - MethodNotificationCenterSwiftTests Definition
1212

13-
class MethodNotificationCenterTests: XCTestCase {
13+
class MethodNotificationCenterSwiftTests: XCTestCase {
1414

1515
// MARK: Test Methods
1616

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

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

2929
MethodNotificationCenter.removeObserver(observer)
3030
}
3131

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

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

4444
MethodNotificationCenter.removeObserver(observer)
4545
}
4646

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

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

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

@@ -99,18 +99,18 @@ class MethodNotificationCenterTests: XCTestCase {
9999

100100
XCTAssertEqual(test.value, 0)
101101
test.perform(#selector(TestClass1.increment))
102-
//test.increment() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
102+
// test.increment() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
103103
XCTAssertEqual(test.value, 3)
104104
test.perform(#selector(TestClass1.incrementBy2))
105-
//test.incrementBy2() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
105+
// test.incrementBy2() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
106106
XCTAssertEqual(test.value, 7)
107107
MethodNotificationCenter.removeObserver(observer2)
108108
test.perform(#selector(TestClass1.incrementBy2))
109-
//test.incrementBy2() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
109+
// test.incrementBy2() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
110110
XCTAssertEqual(test.value, 9)
111111
MethodNotificationCenter.removeObserver(observer)
112112
test.perform(#selector(TestClass1.increment))
113-
//test.increment() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
113+
// test.increment() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
114114
XCTAssertEqual(test.value, 10)
115115
}
116116

@@ -139,30 +139,30 @@ class MethodNotificationCenterTests: XCTestCase {
139139
XCTAssertEqual(test2.value, 0)
140140
test.perform(#selector(TestClass1.increment))
141141
test2.perform(#selector(TestClass1.increment))
142-
//test.increment() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
143-
//test2.increment() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
142+
// test.increment() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
143+
// test2.increment() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
144144
XCTAssertEqual(test.value, 3)
145145
XCTAssertEqual(test2.value, 3)
146146
test.perform(#selector(TestClass1.incrementBy2))
147147
test2.perform(#selector(TestClass1.incrementBy2))
148-
//test.incrementBy2() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
149-
//test2.incrementBy2() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
148+
// test.incrementBy2() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
149+
// test2.incrementBy2() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
150150
XCTAssertEqual(test.value, 7)
151151
XCTAssertEqual(test2.value, 7)
152152
MethodNotificationCenter.removeObserver(observer2)
153153
MethodNotificationCenter.removeObserver(observer4)
154154
test.perform(#selector(TestClass1.incrementBy2))
155155
test2.perform(#selector(TestClass1.incrementBy2))
156-
//test.incrementBy2() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
157-
//test2.incrementBy2() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
156+
// test.incrementBy2() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
157+
// test2.incrementBy2() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
158158
XCTAssertEqual(test.value, 9)
159159
XCTAssertEqual(test2.value, 9)
160160
MethodNotificationCenter.removeObserver(observer)
161161
MethodNotificationCenter.removeObserver(observer3)
162162
test.perform(#selector(TestClass1.increment))
163163
test2.perform(#selector(TestClass1.increment))
164-
//test.increment() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
165-
//test2.increment() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
164+
// test.increment() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
165+
// test2.increment() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
166166
XCTAssertEqual(test.value, 10)
167167
XCTAssertEqual(test2.value, 10)
168168
}
@@ -189,7 +189,7 @@ class MethodNotificationCenterTests: XCTestCase {
189189

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

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

209209
XCTAssertEqual(test.value, 0)
210210
test.perform(#selector(TestClass1.increment))
211-
//test.increment() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
211+
// test.increment() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
212212
XCTAssertEqual(test.value, 3)
213213
unmanagedObserver.release() // causes observer to be overreleased, but that's okay for our unit testing
214214
test.perform(#selector(TestClass1.increment))
215-
//test.increment() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
215+
// test.increment() // Can't call directly in Swift as the complier will skip the ObjC runtime and call the Swift function directly
216216
XCTAssertEqual(test.value, 4)
217217
}
218218
}

scripts/carthage.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env bash
2-
2+
#
33
# Needed to circumvent an issue with Carthage version < 0.37.0: https://github.com/Carthage/Carthage/issues/3019
44
#
55
# carthage.sh

scripts/resolvepath.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env bash
2-
2+
#
33
# resolvepath.sh
44
# Usage example: ./resolvepath.sh "./some/random/path/../../"
55

0 commit comments

Comments
 (0)