-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #136 from BarredEwe/swiftPM
Added support for swift package manager
- Loading branch information
Showing
30 changed files
with
397 additions
and
404 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"object": { | ||
"pins": [ | ||
{ | ||
"package": "Swinject", | ||
"repositoryURL": "https://github.com/Swinject/Swinject.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "8a76d2c74bafbb455763487cc6a08e91bad1f78b", | ||
"version": "2.7.1" | ||
} | ||
} | ||
] | ||
}, | ||
"version": 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// swift-tools-version:5.3 | ||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "SwinjectStoryboard", | ||
platforms: [ | ||
.macOS(.v10_10), | ||
.iOS(.v9), | ||
.tvOS(.v9), | ||
], | ||
products: [ | ||
.library(name: "SwinjectStoryboard", targets: ["SwinjectStoryboard"]), | ||
], | ||
dependencies: [ | ||
.package(url: "https://github.com/Swinject/Swinject.git", .upToNextMajor(from: "2.7.1")), | ||
], | ||
targets: [ | ||
.target( | ||
name: "SwinjectStoryboard-ObjC", | ||
path: "Sources/ObjectiveC", | ||
cSettings: [ | ||
.headerSearchPath("Others") | ||
] | ||
), | ||
.target( | ||
name: "SwinjectStoryboard", | ||
dependencies: [ | ||
"Swinject", | ||
"SwinjectStoryboard-ObjC" | ||
], | ||
path: "Sources", | ||
exclude: [ | ||
"ObjectiveC", | ||
"Info.plist" | ||
] | ||
), | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import Foundation | ||
|
||
internal extension DispatchQueue { | ||
|
||
private static var _onceTracker: [String] = [] | ||
|
||
static func once(token: String, block: () -> Void) { | ||
objc_sync_enter(self) | ||
defer { objc_sync_exit(self) } | ||
|
||
if _onceTracker.contains(token) { | ||
return | ||
} | ||
|
||
_onceTracker.append(token) | ||
block() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#if canImport(Cocoa) | ||
import Cocoa | ||
|
||
extension NSStoryboard { | ||
static func swizzling() { | ||
DispatchQueue.once(token: "swinject.storyboard.init") { | ||
let aClass: AnyClass = object_getClass(self)! | ||
|
||
let originalSelector = #selector(NSStoryboard.init(name:bundle:)) | ||
let swizzledSelector = #selector(swinject_init(name:bundle:)) | ||
|
||
let originalMethod = class_getInstanceMethod(aClass, originalSelector)! | ||
let swizzledMethod = class_getInstanceMethod(aClass, swizzledSelector)! | ||
|
||
let didAddMethod = class_addMethod(aClass, originalSelector, | ||
method_getImplementation(swizzledMethod), | ||
method_getTypeEncoding(swizzledMethod)) | ||
|
||
guard didAddMethod else { | ||
method_exchangeImplementations(originalMethod, swizzledMethod) | ||
return | ||
} | ||
class_replaceMethod(aClass, swizzledSelector, | ||
method_getImplementation(originalMethod), | ||
method_getTypeEncoding(originalMethod)) | ||
} | ||
} | ||
|
||
@objc class func swinject_init(name: String, bundle: Bundle?) -> NSStoryboard { | ||
guard self == NSStoryboard.self else { | ||
return self.swinject_init(name: name, bundle: bundle) | ||
} | ||
// Instantiate SwinjectStoryboard if NSStoryboard is trying to be instantiated. | ||
if SwinjectStoryboard.isCreatingStoryboardReference { | ||
return SwinjectStoryboard.createReferenced(name: name, bundle: bundle) | ||
} else { | ||
return SwinjectStoryboard.create(name: name, bundle: bundle) | ||
} | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#if canImport(Cocoa) | ||
import Cocoa | ||
import Swinject | ||
|
||
@objcMembers | ||
public class _SwinjectStoryboardBase: NSStoryboard { | ||
public class func _create(_ name: String, bundle storyboardBundleOrNil: Bundle?) -> Self { | ||
let storyboard = perform(#selector(NSStoryboard.init(name:bundle:)), with: name, with: storyboardBundleOrNil)? | ||
.takeUnretainedValue() | ||
return storyboard as! Self | ||
} | ||
} | ||
|
||
extension SwinjectStoryboard { | ||
@objc public static func configure() { | ||
NSStoryboard.swizzling() | ||
DispatchQueue.once(token: "swinject.storyboard.setup") { | ||
guard SwinjectStoryboard.responds(to: _Selector("setup")) else { return } | ||
SwinjectStoryboard.perform(_Selector("setup")) | ||
} | ||
} | ||
|
||
static func _Selector(_ str: String) -> Selector { | ||
return Selector(str) | ||
} | ||
} | ||
#endif |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// SwinjectStoryboard+SetUp.m | ||
// SwinjectStoryboard | ||
// | ||
// Created by Mark DiFranco on 2017-05-27. | ||
// Copyright © 2017 Swinject Contributors. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
__attribute__((constructor)) static void swinjectStoryboardSetupEntry(void) { | ||
Class swinjectStoryboard = NSClassFromString(@"SwinjectStoryboard"); | ||
#pragma clang diagnostic push | ||
#pragma clang diagnostic ignored "-Wundeclared-selector" | ||
if ([swinjectStoryboard respondsToSelector:@selector(configure)]) { | ||
[swinjectStoryboard performSelector:@selector(configure)]; | ||
} | ||
#pragma clang diagnostic pop | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.