Skip to content

Commit

Permalink
Merge pull request #52 from iiiCeBlink/dev-load
Browse files Browse the repository at this point in the history
Fix #51 and remove load method referenced from objc files (compatibility with Swift 5 and Xcode 10.2)
  • Loading branch information
pmusolino authored Mar 26, 2019
2 parents ac1e126 + a6cea04 commit 7879f46
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 49 deletions.
8 changes: 2 additions & 6 deletions Sources/Objc/NSURLSessionConfiguration+Wormholy.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@
return config;
}

@implementation NSURLSessionConfiguration (Wormholy)

+(void)load
{
__attribute__((constructor)) static void sessionConfigurationInjectEntry(void) {

orig_defaultSessionConfiguration = (SessionConfigConstructor)WormholyReplaceMethod(@selector(defaultSessionConfiguration),
(IMP)Wormholy_defaultSessionConfiguration,
[NSURLSessionConfiguration class],
Expand All @@ -49,5 +47,3 @@ +(void)load
YES);
}


@end
15 changes: 0 additions & 15 deletions Sources/Objc/Wormholy+Foo.h

This file was deleted.

19 changes: 0 additions & 19 deletions Sources/Objc/Wormholy+Foo.m

This file was deleted.

46 changes: 46 additions & 0 deletions Sources/Utils/SwiftySelfAwareHelper.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// SwiftySelfAwareHelper.swift
// Wormholy
//
// Created by Kealdish on 2019/2/28.
// Copyright © 2019 Wormholy. All rights reserved.
//

import Foundation
import UIKit

protocol SelfAware: class {
static func awake()
}

struct CustomSelfAwareHelper {

static func harmlessFunction() {

// Get all class list through runtime
let typeCount = Int(objc_getClassList(nil, 0))
let types = UnsafeMutablePointer<AnyClass>.allocate(capacity: typeCount)
let autoreleasingTypes = AutoreleasingUnsafeMutablePointer<AnyClass>(types)
objc_getClassList(autoreleasingTypes, Int32(typeCount))

for index in 0 ..< typeCount {
(types[index] as? SelfAware.Type)?.awake()
}

types.deallocate()
}
}

extension UIApplication {

private static let runOnce: Void = {
CustomSelfAwareHelper.harmlessFunction()
}()

override open var next: UIResponder? {
// Called before applicationDidFinishLaunching
UIApplication.runOnce
return super.next
}

}
1 change: 0 additions & 1 deletion Sources/Wormholy.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@


#import "NSURLSessionConfiguration+Wormholy.h"
#import "Wormholy+Foo.h"
#import "WormholyMethodSwizzling.h"


Expand Down
12 changes: 12 additions & 0 deletions Sources/Wormholy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,15 @@ public class Wormholy: NSObject
return true
}()
}

extension Wormholy: SelfAware {

static func awake() {
initializeAction
}

private static let initializeAction: Void = {
swiftyLoad()
swiftyInitialize()
}()
}
12 changes: 4 additions & 8 deletions Wormholy.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
455818C9207D621200D2F954 /* RequestModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 455818C8207D621200D2F954 /* RequestModel.swift */; };
455818D5207D64A900D2F954 /* WormholyMethodSwizzling.m in Sources */ = {isa = PBXBuildFile; fileRef = 455818CF207D64A800D2F954 /* WormholyMethodSwizzling.m */; };
455818D6207D64A900D2F954 /* NSURLSessionConfiguration+Wormholy.m in Sources */ = {isa = PBXBuildFile; fileRef = 455818D0207D64A800D2F954 /* NSURLSessionConfiguration+Wormholy.m */; };
455818D8207D64A900D2F954 /* Wormholy+Foo.m in Sources */ = {isa = PBXBuildFile; fileRef = 455818D2207D64A800D2F954 /* Wormholy+Foo.m */; };
455818D9207D64A900D2F954 /* NSURLSessionConfiguration+Wormholy.h in Headers */ = {isa = PBXBuildFile; fileRef = 455818D3207D64A800D2F954 /* NSURLSessionConfiguration+Wormholy.h */; settings = {ATTRIBUTES = (Public, ); }; };
455818DA207D64A900D2F954 /* WormholyMethodSwizzling.h in Headers */ = {isa = PBXBuildFile; fileRef = 455818D4207D64A800D2F954 /* WormholyMethodSwizzling.h */; settings = {ATTRIBUTES = (Public, ); }; };
45820CF6208170F400CA74D6 /* Colors.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45820CF5208170F400CA74D6 /* Colors.swift */; };
Expand All @@ -51,7 +50,6 @@
45C4F4F320860FBC007D0D17 /* WHTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45C4F4F220860FBC007D0D17 /* WHTextView.swift */; };
45C51A1820A20B38006933CE /* Wormholy.h in Headers */ = {isa = PBXBuildFile; fileRef = 45C51A1720A20B38006933CE /* Wormholy.h */; settings = {ATTRIBUTES = (Public, ); }; };
45DB6DAF2083E738009494AE /* RequestDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45DB6DAE2083E738009494AE /* RequestDetailViewController.swift */; };
45F51C1E20BC8DDB002CB534 /* Wormholy+Foo.h in Headers */ = {isa = PBXBuildFile; fileRef = 455818D1207D64A800D2F954 /* Wormholy+Foo.h */; settings = {ATTRIBUTES = (Public, ); }; };
45FF5C4A20875EFA0084BD50 /* WHView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45FF5C4920875EFA0084BD50 /* WHView.swift */; };
45FF5C4C20875F710084BD50 /* RequestTitleSectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45FF5C4B20875F710084BD50 /* RequestTitleSectionView.swift */; };
45FF5C4E20875F770084BD50 /* RequestTitleSectionView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 45FF5C4D20875F770084BD50 /* RequestTitleSectionView.xib */; };
Expand All @@ -60,6 +58,7 @@
52D6D9871BEFF229002C0205 /* Wormholy.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 52D6D97C1BEFF229002C0205 /* Wormholy.framework */; };
8933C7851EB5B820000D00A4 /* Wormholy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8933C7841EB5B820000D00A4 /* Wormholy.swift */; };
8933C7901EB5B82D000D00A4 /* WormholyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8933C7891EB5B82A000D00A4 /* WormholyTests.swift */; };
93A86AB12228349F006E56FB /* SwiftySelfAwareHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93A86AB02228349F006E56FB /* SwiftySelfAwareHelper.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -105,8 +104,6 @@
455818C8207D621200D2F954 /* RequestModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RequestModel.swift; sourceTree = "<group>"; };
455818CF207D64A800D2F954 /* WormholyMethodSwizzling.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WormholyMethodSwizzling.m; sourceTree = "<group>"; };
455818D0207D64A800D2F954 /* NSURLSessionConfiguration+Wormholy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSURLSessionConfiguration+Wormholy.m"; sourceTree = "<group>"; };
455818D1207D64A800D2F954 /* Wormholy+Foo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "Wormholy+Foo.h"; sourceTree = "<group>"; };
455818D2207D64A800D2F954 /* Wormholy+Foo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "Wormholy+Foo.m"; sourceTree = "<group>"; };
455818D3207D64A800D2F954 /* NSURLSessionConfiguration+Wormholy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSURLSessionConfiguration+Wormholy.h"; sourceTree = "<group>"; };
455818D4207D64A800D2F954 /* WormholyMethodSwizzling.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WormholyMethodSwizzling.h; sourceTree = "<group>"; };
45820CF5208170F400CA74D6 /* Colors.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Colors.swift; sourceTree = "<group>"; };
Expand All @@ -129,6 +126,7 @@
52D6D9861BEFF229002C0205 /* Wormholy-iOS Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Wormholy-iOS Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
8933C7841EB5B820000D00A4 /* Wormholy.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Wormholy.swift; sourceTree = "<group>"; };
8933C7891EB5B82A000D00A4 /* WormholyTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WormholyTests.swift; sourceTree = "<group>"; };
93A86AB02228349F006E56FB /* SwiftySelfAwareHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftySelfAwareHelper.swift; sourceTree = "<group>"; };
AD2FAA261CD0B6D800659CF4 /* Wormholy.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Wormholy.plist; sourceTree = "<group>"; };
AD2FAA281CD0B6E100659CF4 /* WormholyTests.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = WormholyTests.plist; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -252,6 +250,7 @@
children = (
454BBA372087B66200EB13E9 /* RequestModelBeautifier.swift */,
452CC13321773BF600CB5E21 /* FileHandler.swift */,
93A86AB02228349F006E56FB /* SwiftySelfAwareHelper.swift */,
);
path = Utils;
sourceTree = "<group>";
Expand All @@ -270,8 +269,6 @@
children = (
455818D3207D64A800D2F954 /* NSURLSessionConfiguration+Wormholy.h */,
455818D0207D64A800D2F954 /* NSURLSessionConfiguration+Wormholy.m */,
455818D1207D64A800D2F954 /* Wormholy+Foo.h */,
455818D2207D64A800D2F954 /* Wormholy+Foo.m */,
455818D4207D64A800D2F954 /* WormholyMethodSwizzling.h */,
455818CF207D64A800D2F954 /* WormholyMethodSwizzling.m */,
);
Expand Down Expand Up @@ -368,7 +365,6 @@
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
45F51C1E20BC8DDB002CB534 /* Wormholy+Foo.h in Headers */,
45C51A1820A20B38006933CE /* Wormholy.h in Headers */,
455818DA207D64A900D2F954 /* WormholyMethodSwizzling.h in Headers */,
455818D9207D64A900D2F954 /* NSURLSessionConfiguration+Wormholy.h in Headers */,
Expand Down Expand Up @@ -534,6 +530,7 @@
451C9E582080E607002A34BC /* WHNavigationController.swift in Sources */,
455818D6207D64A900D2F954 /* NSURLSessionConfiguration+Wormholy.m in Sources */,
8933C7851EB5B820000D00A4 /* Wormholy.swift in Sources */,
93A86AB12228349F006E56FB /* SwiftySelfAwareHelper.swift in Sources */,
455818C4207D61A100D2F954 /* Storage.swift in Sources */,
45FF5C4C20875F710084BD50 /* RequestTitleSectionView.swift in Sources */,
45DB6DAF2083E738009494AE /* RequestDetailViewController.swift in Sources */,
Expand All @@ -556,7 +553,6 @@
455818D5207D64A900D2F954 /* WormholyMethodSwizzling.m in Sources */,
45FF5C54208794720084BD50 /* WHDate.swift in Sources */,
454BBA382087B66200EB13E9 /* RequestModelBeautifier.swift in Sources */,
455818D8207D64A900D2F954 /* Wormholy+Foo.m in Sources */,
451C9E65208106D1002A34BC /* WHLabel.swift in Sources */,
451C9E6720810B4C002A34BC /* RequestCell.swift in Sources */,
);
Expand Down

0 comments on commit 7879f46

Please sign in to comment.