Skip to content

Commit bd52a84

Browse files
committed
Use a better prefix for classes and methods
1 parent e041606 commit bd52a84

File tree

11 files changed

+105
-92
lines changed

11 files changed

+105
-92
lines changed

FRZSwizzling.xcodeproj/project.pbxproj

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
7B8E47D524840E9700FA751E /* FRZSwizzlingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B8BD034200274B9009BE667 /* FRZSwizzlingTests.swift */; };
1414
7BC0AFB52235679400EF4920 /* NSObject+FRZSwizzling.m in Sources */ = {isa = PBXBuildFile; fileRef = 7BC0AFB12235679400EF4920 /* NSObject+FRZSwizzling.m */; };
1515
7BC0AFB72235679400EF4920 /* NSObject+FRZSwizzling.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BC0AFB22235679400EF4920 /* NSObject+FRZSwizzling.h */; settings = {ATTRIBUTES = (Public, ); }; };
16-
7BC0AFC022356A5000EF4920 /* FRZSimpleObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 7BC0AFBF22356A5000EF4920 /* FRZSimpleObject.m */; };
17-
7BC0AFC322356C9000EF4920 /* FRZSimpleObject+Swizzling.m in Sources */ = {isa = PBXBuildFile; fileRef = 7BC0AFC222356C9000EF4920 /* FRZSimpleObject+Swizzling.m */; };
16+
7BC0AFC022356A5000EF4920 /* FSZSimpleObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 7BC0AFBF22356A5000EF4920 /* FSZSimpleObject.m */; };
17+
7BC0AFC322356C9000EF4920 /* FSZSimpleObject+Swizzling.m in Sources */ = {isa = PBXBuildFile; fileRef = 7BC0AFC222356C9000EF4920 /* FSZSimpleObject+Swizzling.m */; };
1818
/* End PBXBuildFile section */
1919

2020
/* Begin PBXContainerItemProxy section */
@@ -23,7 +23,7 @@
2323
containerPortal = 7B661F9320026ACC00486182 /* Project object */;
2424
proxyType = 1;
2525
remoteGlobalIDString = 7B8BD01920026E8C009BE667;
26-
remoteInfo = "happnLogger-macOS";
26+
remoteInfo = FRZSwizzling;
2727
};
2828
/* End PBXContainerItemProxy section */
2929

@@ -43,10 +43,10 @@
4343
7BC0AFB12235679400EF4920 /* NSObject+FRZSwizzling.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSObject+FRZSwizzling.m"; sourceTree = "<group>"; };
4444
7BC0AFB22235679400EF4920 /* NSObject+FRZSwizzling.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSObject+FRZSwizzling.h"; sourceTree = "<group>"; };
4545
7BC0AFBD22356A4F00EF4920 /* FRZSwizzling-Tests-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "FRZSwizzling-Tests-Bridging-Header.h"; sourceTree = "<group>"; };
46-
7BC0AFBE22356A5000EF4920 /* FRZSimpleObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FRZSimpleObject.h; sourceTree = "<group>"; };
47-
7BC0AFBF22356A5000EF4920 /* FRZSimpleObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FRZSimpleObject.m; sourceTree = "<group>"; };
48-
7BC0AFC222356C9000EF4920 /* FRZSimpleObject+Swizzling.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "FRZSimpleObject+Swizzling.m"; sourceTree = "<group>"; };
49-
7BC0AFC42235763E00EF4920 /* FRZSimpleObject+Swizzling.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "FRZSimpleObject+Swizzling.h"; sourceTree = "<group>"; };
46+
7BC0AFBE22356A5000EF4920 /* FSZSimpleObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSZSimpleObject.h; sourceTree = "<group>"; };
47+
7BC0AFBF22356A5000EF4920 /* FSZSimpleObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FSZSimpleObject.m; sourceTree = "<group>"; };
48+
7BC0AFC222356C9000EF4920 /* FSZSimpleObject+Swizzling.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "FSZSimpleObject+Swizzling.m"; sourceTree = "<group>"; };
49+
7BC0AFC42235763E00EF4920 /* FSZSimpleObject+Swizzling.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "FSZSimpleObject+Swizzling.h"; sourceTree = "<group>"; };
5050
/* End PBXFileReference section */
5151

5252
/* Begin PBXFrameworksBuildPhase section */
@@ -68,6 +68,13 @@
6868
/* End PBXFrameworksBuildPhase section */
6969

7070
/* Begin PBXGroup section */
71+
7B0F46202B8E8BEE001CEC48 /* Frameworks */ = {
72+
isa = PBXGroup;
73+
children = (
74+
);
75+
name = Frameworks;
76+
sourceTree = "<group>";
77+
};
7178
7B661F9220026ACC00486182 = {
7279
isa = PBXGroup;
7380
children = (
@@ -78,6 +85,7 @@
7885
7B8BD031200274B9009BE667 /* Tests */,
7986
7B8BD01B20026E8C009BE667 /* Xcode Supporting Files */,
8087
7B661F9C20026ACC00486182 /* Products */,
88+
7B0F46202B8E8BEE001CEC48 /* Frameworks */,
8189
);
8290
indentWidth = 3;
8391
sourceTree = "<group>";
@@ -128,10 +136,10 @@
128136
7BC0AFBC22356A0400EF4920 /* Helpers */ = {
129137
isa = PBXGroup;
130138
children = (
131-
7BC0AFBE22356A5000EF4920 /* FRZSimpleObject.h */,
132-
7BC0AFBF22356A5000EF4920 /* FRZSimpleObject.m */,
133-
7BC0AFC42235763E00EF4920 /* FRZSimpleObject+Swizzling.h */,
134-
7BC0AFC222356C9000EF4920 /* FRZSimpleObject+Swizzling.m */,
139+
7BC0AFBE22356A5000EF4920 /* FSZSimpleObject.h */,
140+
7BC0AFBF22356A5000EF4920 /* FSZSimpleObject.m */,
141+
7BC0AFC42235763E00EF4920 /* FSZSimpleObject+Swizzling.h */,
142+
7BC0AFC222356C9000EF4920 /* FSZSimpleObject+Swizzling.m */,
135143
);
136144
path = Helpers;
137145
sourceTree = "<group>";
@@ -165,7 +173,7 @@
165173
dependencies = (
166174
);
167175
name = FRZSwizzling;
168-
productName = "happnLogger-macOS";
176+
productName = FRZSwizzling;
169177
productReference = 7B8BD01A20026E8C009BE667 /* FRZSwizzling.framework */;
170178
productType = "com.apple.product-type.framework";
171179
};
@@ -183,7 +191,7 @@
183191
7B8BD02520026E8C009BE667 /* PBXTargetDependency */,
184192
);
185193
name = FRZSwizzlingTests;
186-
productName = "happnLogger-macOSTests";
194+
productName = FRZSwizzlingTests;
187195
productReference = 7B8BD02220026E8C009BE667 /* FRZSwizzlingTests.xctest */;
188196
productType = "com.apple.product-type.bundle.unit-test";
189197
};
@@ -194,6 +202,7 @@
194202
isa = PBXProject;
195203
attributes = {
196204
BuildIndependentTargetsInParallel = YES;
205+
CLASSPREFIX = FSZ;
197206
LastSwiftUpdateCheck = 0920;
198207
LastUpgradeCheck = 1520;
199208
ORGANIZATIONNAME = "François Lamboley";
@@ -260,9 +269,9 @@
260269
isa = PBXSourcesBuildPhase;
261270
buildActionMask = 2147483647;
262271
files = (
263-
7BC0AFC022356A5000EF4920 /* FRZSimpleObject.m in Sources */,
264-
7BC0AFC322356C9000EF4920 /* FRZSimpleObject+Swizzling.m in Sources */,
265272
7B8E47D524840E9700FA751E /* FRZSwizzlingTests.swift in Sources */,
273+
7BC0AFC022356A5000EF4920 /* FSZSimpleObject.m in Sources */,
274+
7BC0AFC322356C9000EF4920 /* FSZSimpleObject+Swizzling.m in Sources */,
266275
);
267276
runOnlyForDeploymentPostprocessing = 0;
268277
};
@@ -350,7 +359,7 @@
350359
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
351360
SWIFT_VERSION = 5.0;
352361
TVOS_DEPLOYMENT_TARGET = 12.0;
353-
VERSION_INFO_PREFIX = FRZ;
362+
VERSION_INFO_PREFIX = FSZ;
354363
WATCHOS_DEPLOYMENT_TARGET = 4.0;
355364
XROS_DEPLOYMENT_TARGET = 1.0;
356365
};
@@ -423,7 +432,7 @@
423432
SWIFT_VERSION = 5.0;
424433
TVOS_DEPLOYMENT_TARGET = 12.0;
425434
VALIDATE_PRODUCT = YES;
426-
VERSION_INFO_PREFIX = FRZ;
435+
VERSION_INFO_PREFIX = FSZ;
427436
WATCHOS_DEPLOYMENT_TARGET = 4.0;
428437
XROS_DEPLOYMENT_TARGET = 1.0;
429438
};

Readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ static void MySetFrame(id self, SEL _cmd, CGRect frame) {
2828

2929
+ (void)load
3030
{
31-
CHECKED_SWIZZLE(NSView, setFrame:, MySetFrame, OriginalSetFrame);
31+
FSZ_CHECKED_SWIZZLE(NSView, setFrame:, MySetFrame, OriginalSetFrame);
3232
}
3333

3434
@end
3535
```
3636
3737
## Developers Notes
3838
The include folder in the FRZSwizzling source code folder is there for SPM-compatibility.
39-
It contains a special `FRZSwizzling.h` umbrella header and a soft link to the other header.
39+
It contains a special `FRZSwizzling.h` umbrella header and a soft link to the other (public) header.
4040
4141
## Credits
4242
This project was originally created by [François Lamboley](https://github.com/Frizlab) while working at [happn](https://happn.com).

Sources/NSObject+FRZSwizzling.h

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ limitations under the License. */
2323

2424

2525
/* Stringification. */
26-
#define _FRZsharp(x) #x
27-
#define FRZS(x) _FRZsharp(x)
26+
#define _FSZsharp(x) #x
27+
#define FSZ_S(x) _FSZsharp(x)
2828

2929
typedef IMP *IMPPointer;
3030

@@ -53,7 +53,7 @@ static void MySetFrame(id self, SEL _cmd, CGRect frame) {
5353
5454
+ (void)load
5555
{
56-
CHECKED_SWIZZLE(NSView, setFrame:, MySetFrame, OriginalSetFrame);
56+
FSZ_CHECKED_SWIZZLE(NSView, setFrame:, MySetFrame, OriginalSetFrame);
5757
}
5858
5959
@end
@@ -63,10 +63,10 @@ static void MySetFrame(id self, SEL _cmd, CGRect frame) {
6363
/**
6464
Swizzle a method in the receiver’s class.
6565
66-
Fixes parent swizzling by default (see ``hpn_swizzleOrAdd:with:store:typesSelector:didAdd:fixChildrenSwizzling:`` for more info). */
67-
+ (BOOL)hpn_swizzle:(SEL)original with:(IMP)replacement store:(IMPPointer)store;
68-
/** Calls ``hpn_swizzleOrAdd:with:store:typesSelector:didAdd:fixChildrenSwizzling:`` with `fixChildrenSwizzling` set to `YES`. */
69-
+ (BOOL)hpn_swizzleOrAdd:(SEL)original with:(IMP)replacement store:(IMPPointer)store
66+
Fixes parent swizzling by default (see ``fsz_swizzleOrAdd:with:store:typesSelector:didAdd:fixChildrenSwizzling:`` for more info). */
67+
+ (BOOL)fsz_swizzle:(SEL)original with:(IMP)replacement store:(IMPPointer)store;
68+
/** Calls ``fsz_swizzleOrAdd:with:store:typesSelector:didAdd:fixChildrenSwizzling:`` with `fixChildrenSwizzling` set to `YES`. */
69+
+ (BOOL)fsz_swizzleOrAdd:(SEL)original with:(IMP)replacement store:(IMPPointer)store
7070
typesSelector:(SEL)backupSelector didAdd:(BOOL *)didAddPtr;
7171

7272
/**
@@ -96,7 +96,7 @@ static void MySetFrame(id self, SEL _cmd, CGRect frame) {
9696
It is highly recommended that you keep a reference to the original implementation of the method using the store variable:
9797
when you swizzle a method, you practically always have to call the original method.
9898
(Giving a `NULL` `store` will print a warning in the logs.) */
99-
+ (BOOL)hpn_swizzleOrAdd:(SEL)original with:(IMP)replacement store:(IMPPointer)store
99+
+ (BOOL)fsz_swizzleOrAdd:(SEL)original with:(IMP)replacement store:(IMPPointer)store
100100
typesSelector:(SEL)typesSelector didAdd:(BOOL *)didAddPtr
101101
fixChildrenSwizzling:(BOOL)fixChildrenSwizzling;
102102

@@ -105,8 +105,8 @@ static void MySetFrame(id self, SEL _cmd, CGRect frame) {
105105
The selector is added only if it was not present in the class.
106106
107107
Returns `NO` if the method was not added (it is already in the class, or there is an error getting the types to add the method).
108-
Calls ``hpn_addOnlyIfNotExist:with:typesSelector:store:`` with `store` set to `NULL`. */
109-
+ (BOOL)hpn_addOnlyIfNotExist:(SEL)added with:(IMP)implementation typesSelector:(SEL)typesSelector;
108+
Calls ``fsz_addOnlyIfNotExist:with:typesSelector:store:`` with `store` set to `NULL`. */
109+
+ (BOOL)fsz_addOnlyIfNotExist:(SEL)added with:(IMP)implementation typesSelector:(SEL)typesSelector;
110110

111111
/**
112112
Add a new instance selector in the class.
@@ -120,13 +120,13 @@ static void MySetFrame(id self, SEL _cmd, CGRect frame) {
120120
121121
- Note: If store is non-`NULL`, it must always point to a valid memory location while the application is launched
122122
(unless you don’t plan on fixing children swizzling).
123-
(This is the same rule as the `hpn_swizzleOrAdd:...` methods.) */
124-
+ (BOOL)hpn_addOnlyIfNotExist:(SEL)added with:(IMP)implementation typesSelector:(SEL)typesSelector store:(IMPPointer)store;
123+
(This is the same rule as the `fsz_swizzleOrAdd:...` methods.) */
124+
+ (BOOL)fsz_addOnlyIfNotExist:(SEL)added with:(IMP)implementation typesSelector:(SEL)typesSelector store:(IMPPointer)store;
125125

126126
/**
127127
Any further swizzling (by methods from this category) of the given selector on any superclass of the calling class or the calling class
128128
will throw an exception after this method is called. */
129-
+ (void)hpn_lockSwizzlingOfSelector:(SEL)sel;
129+
+ (void)fsz_lockSwizzlingOfSelector:(SEL)sel;
130130

131131
@end
132132

@@ -136,15 +136,15 @@ static void MySetFrame(id self, SEL _cmd, CGRect frame) {
136136
  ******************** */
137137
/* Use these if you want to automatically throw an exception if there was an error swizzling/adding methods. */
138138

139-
#define CHECKED_SWIZZLE(theClass, theSelector, IMPFuncName, IMPPointerName) \
140-
if (![theClass hpn_swizzle:@selector(theSelector) with:(IMP)IMPFuncName store:(IMPPointer)&IMPPointerName]) \
141-
[NSException raise:@"Cannot swizzle a method" format:@"Tried to swizzle \""FRZS(theSelector)"\" in class \""FRZS(theClass)"\" with my version, but it failed."]; \
142-
if (IMPPointerName == NULL) [NSException raise:@"Swizzled a method, but original function pointer is NULL" format:@"Swizzled \""FRZS(theSelector)"\", but "FRZS(IMPPointerName)" is NULL."]
139+
#define FSZ_CHECKED_SWIZZLE(theClass, theSelector, IMPFuncName, IMPPointerName) \
140+
if (![theClass fsz_swizzle:@selector(theSelector) with:(IMP)IMPFuncName store:(IMPPointer)&IMPPointerName]) \
141+
[NSException raise:@"Cannot swizzle a method" format:@"Tried to swizzle \""FSZ_S(theSelector)"\" in class \""FSZ_S(theClass)"\" with my version, but it failed."]; \
142+
if (IMPPointerName == NULL) [NSException raise:@"Swizzled a method, but original function pointer is NULL" format:@"Swizzled \""FSZ_S(theSelector)"\", but "FSZ_S(IMPPointerName)" is NULL."]
143143

144-
#define CHECKED_SWIZZLE_OR_ADD(theClass, theSelector, IMPFuncName, IMPPointerName, backupSelector) \
145-
if (![theClass hpn_swizzleOrAdd:@selector(theSelector) with:(IMP)IMPFuncName store:(IMPPointer)&IMPPointerName typesSelector:@selector(backupSelector)]) \
146-
[NSException raise:@"Cannot swizzle or add a method" format:@"Tried to swizzle or add \""FRZS(theSelector)"\" in class \""FRZS(theClass)"\", but it failed."]
144+
#define FSZ_CHECKED_SWIZZLE_OR_ADD(theClass, theSelector, IMPFuncName, IMPPointerName, backupSelector) \
145+
if (![theClass fsz_swizzleOrAdd:@selector(theSelector) with:(IMP)IMPFuncName store:(IMPPointer)&IMPPointerName typesSelector:@selector(backupSelector)]) \
146+
[NSException raise:@"Cannot swizzle or add a method" format:@"Tried to swizzle or add \""FSZ_S(theSelector)"\" in class \""FSZ_S(theClass)"\", but it failed."]
147147

148-
#define CHECKED_ADD_ONLY_IF_NOT_EXIST(theClass, theSelector, IMPFuncName, theTypesSelector) \
149-
if (![theClass hpn_addOnlyIfNotExist:@selector(theSelector) with:(IMP)IMPFuncName typesSelector:@selector(theTypesSelector)]) \
150-
[NSException raise:@"Cannot add method only if not exist" format:@"Tried to add \""FRZS(theSelector)"\" only if does not exist in class \""FRZS(theClass)"\", but it failed. Maybe it does exist?"]
148+
#define FSZ_CHECKED_ADD_ONLY_IF_NOT_EXIST(theClass, theSelector, IMPFuncName, theTypesSelector) \
149+
if (![theClass fsz_addOnlyIfNotExist:@selector(theSelector) with:(IMP)IMPFuncName typesSelector:@selector(theTypesSelector)]) \
150+
[NSException raise:@"Cannot add method only if not exist" format:@"Tried to add \""FSZ_S(theSelector)"\" only if does not exist in class \""FSZ_S(theClass)"\", but it failed. Maybe it does exist?"]

0 commit comments

Comments
 (0)