Skip to content
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ try #swizzle(UIViewController.viewDidLoad) { $self in
print("After")
}

try #swizzle(UIViewController.viewDidAppear, param: Bool.self) { $self, animated in
try #swizzle(UIViewController.viewDidAppear, params: Bool.self) { $self, animated in
print("Before")
self.viewDidAppear(animated)
print("After")
Expand Down
28 changes: 2 additions & 26 deletions Sources/Swizzling/Macros.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,7 @@ public macro swizzle<Object, Param>(

// MARK: Functions - Non Returning

// NOTE: this is only needed because some weird behavior in the compiler causes the variadic
// version below to throw a false positive error when passing a single param under very specific
// conditions. This version is a workaround that can be used in those cases.
//
// Reproducible case:
// ```swift
// try #swizzle(
// SUT.functionWithParamsWithoutReturn,
// params: Int.self
// ) { $self, state in
// self.functionWithParamsWithoutReturn(state) // 🛑 error: Cannot pass value pack expansion to non-pack parameter of type 'Int'
// }
// ```
@available(*, deprecated, renamed: "swizzle(_:params:implementation:)")
@discardableResult
@freestanding(expression)
public macro swizzle<Object, Param>(
Expand All @@ -51,19 +39,7 @@ public macro swizzle<Object, each Param>(

// MARK: Functions - Returning

// NOTE: this is only needed because some weird behavior in the compiler causes the variadic
// version below to throw a false positive error when passing a single param under very specific
// conditions. This version is a workaround that can be used in those cases.
//
// Reproducible case:
// ```swift
// try #swizzle(
// SUT.functionWithParamsWithReturn,
// params: Int.self,
// returning: Int.self
// ) { $self, state in
// self.functionWithParamsWithReturn(state) // 🛑 error: Cannot pass value pack expansion to non-pack parameter of type 'Int'
// }
@available(*, deprecated, renamed: "swizzle(_:params:returning:implementation:)")
@discardableResult
@freestanding(expression)
public macro swizzle<Object, Param, Result>(
Expand Down
4 changes: 2 additions & 2 deletions Tests/SwizzlingTests/SwizzleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ extension SwizzleTests {
func `swizzle function with parameters and without a return value`() throws {
let hook = try #swizzle(
SUT.functionWithParamsWithoutReturn,
param: Int.self,
params: Int.self,
) { $self, state in
self.functionWithParamsWithoutReturn(state + 1)
}
Expand All @@ -130,7 +130,7 @@ extension SwizzleTests {
func `swizzle function with parameters and a return value`() throws {
let hook = try #swizzle(
SUT.functionWithParamsWithReturn,
param: Int.self,
params: Int.self,
returning: Int.self,
) { $sut, value in
sut.functionWithParamsWithReturn(value + 1)
Expand Down
Loading