-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.m
More file actions
95 lines (78 loc) · 4.86 KB
/
main.m
File metadata and controls
95 lines (78 loc) · 4.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
MyFlightbook for iOS - provides native access to MyFlightbook
pilot's logbook
Copyright (C) 2017-2021 MyFlightbook, LLC
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//
// main.m
// MFBSample
//
// Created by Eric Berman on 11/28/09.
// Copyright-2009-2021 MyFlightbook LLC. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <objc/runtime.h>
#import <MyFlightbook-Swift.h>
void Swizzle(Class c, SEL orig, SEL new)
{
Method origMethod = class_getInstanceMethod(c, orig);
Method newMethod = class_getInstanceMethod(c, new);
if(class_addMethod(c, orig, method_getImplementation(newMethod), method_getTypeEncoding(newMethod)))
class_replaceMethod(c, new, method_getImplementation(origMethod), method_getTypeEncoding(origMethod));
else
method_exchangeImplementations(origMethod, newMethod);
}
void SwizzleArchivedClasses(void);
void SwizzleArchivedClasses(void)
{
/*
Swizzle the classes that where we replace initwithcoder/decode
Way back when, I implemented my own initwithcoder/encodewithcoder category extensions on these
classes (before I knew what I was doing). Alas, I need to keep those implementations, and furthermore
the ones that come from wsdl2objC don't seem to work (or at least aren't backwards compatible). Subclassing
doesn't do what I want because the objects are created in the auto-generated code and hence aren't of the
subclass type; I need to extend the actual object.
It all sorta worked for a few years, but the linker warnings got more and more annoying.
The correct way, it seems, to do this is to "swizzle" the functions, effectively swapping their function
with mine. This eliminates the linker warning (since there is no longer a name conflict) and calls my functionality
where I want it.
Swizzling code & description described at https://nshipster.com/method-swizzling/
*/
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Swizzle([MFBWebServiceSvc_Aircraft class], @selector(initWithCoder:), @selector(initWithCoderMFB:));
Swizzle([MFBWebServiceSvc_Aircraft class], @selector(encodeWithCoder:), @selector(encodeWithCoderMFB:));
Swizzle([MFBWebServiceSvc_MFBImageInfo class], @selector(initWithCoder:), @selector(initWithCoderMFB:));
Swizzle([MFBWebServiceSvc_MFBImageInfo class], @selector(encodeWithCoder:), @selector(encodeWithCoderMFB:));
Swizzle([MFBWebServiceSvc_ArrayOfMFBImageInfo class], @selector(initWithCoder:), @selector(initWithCoderMFB:));
Swizzle([MFBWebServiceSvc_ArrayOfMFBImageInfo class], @selector(encodeWithCoder:), @selector(encodeWithCoderMFB:));
Swizzle([MFBWebServiceSvc_ArrayOfCustomFlightProperty class], @selector(initWithCoder:), @selector(initWithCoderMFB:));
Swizzle([MFBWebServiceSvc_ArrayOfCustomFlightProperty class], @selector(encodeWithCoder:), @selector(encodeWithCoderMFB:));
Swizzle([MFBWebServiceSvc_CustomPropertyType class], @selector(initWithCoder:), @selector(initWithCoderMFB:));
Swizzle([MFBWebServiceSvc_CustomPropertyType class], @selector(encodeWithCoder:), @selector(encodeWithCoderMFB:));
Swizzle([MFBWebServiceSvc_CustomFlightProperty class], @selector(initWithCoder:), @selector(initWithCoderMFB:));
Swizzle([MFBWebServiceSvc_CustomFlightProperty class], @selector(encodeWithCoder:), @selector(encodeWithCoderMFB:));
Swizzle([MFBWebServiceSvc_LogbookEntry class], @selector(initWithCoder:), @selector(initWithCoderMFB:));
Swizzle([MFBWebServiceSvc_LogbookEntry class], @selector(encodeWithCoder:), @selector(encodeWithCoderMFB:));
Swizzle([MFBWebServiceSvc_PendingFlight class], @selector(initWithCoder:), @selector(initWithCoderMFB:));
Swizzle([MFBWebServiceSvc_PendingFlight class], @selector(encodeWithCoder:), @selector(encodeWithCoderMFB:));
Swizzle([MFBWebServiceSvc_PropertyTemplate class], @selector(initWithCoder:), @selector(initWithCoderMFB:));
Swizzle([MFBWebServiceSvc_PropertyTemplate class], @selector(encodeWithCoder:), @selector(encodeWithCoderMFB:));
});
}
int main(int argc, char *argv[]) {
@autoreleasepool {
SwizzleArchivedClasses();
return UIApplicationMain(argc, argv, nil, NSStringFromClass([MFBAppDelegate class]));
}
}