Skip to content

Commit beae4b8

Browse files
authored
Dynamic member lookup for dependencies (#340)
* Dynamic member lookup for dependencies - Copy of #323 now that we're finally on Swift 5 * Some minor UIKit renames
1 parent fb9d9ab commit beae4b8

File tree

10 files changed

+18
-13
lines changed

10 files changed

+18
-13
lines changed

NeedleFoundation.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sample/MVC/TicTacToe/Sources/AppDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
2222

2323
var window: UIWindow?
2424

25-
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
25+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
2626
registerProviderFactories()
2727

2828
let window = UIWindow(frame: UIScreen.main.bounds)

Sample/MVC/TicTacToe/Sources/Game/GameViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class GameViewController: UIViewController, UICollectionViewDataSource, UICollec
110110

111111
private func showAlert(with title: String, completionHandler handler: @escaping () -> ()) {
112112
let alert = UIAlertController(title: title, message: nil, preferredStyle: .alert)
113-
let closeAction = UIAlertAction(title: "Close Game", style: UIAlertActionStyle.default) { _ in
113+
let closeAction = UIAlertAction(title: "Close Game", style: UIAlertAction.Style.default) { _ in
114114
handler()
115115
}
116116
alert.addAction(closeAction)

Sample/MVC/TicTacToe/Sources/LoggedOut/LoggedOutViewController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class LoggedOutViewController: UIViewController {
4545
private func buildPlayerFields() -> (player1Field: UITextField, player2Field: UITextField) {
4646
let player1Field = UITextField()
4747
self.player1Field = player1Field
48-
player1Field.borderStyle = UITextBorderStyle.line
48+
player1Field.borderStyle = UITextField.BorderStyle.line
4949
view.addSubview(player1Field)
5050
player1Field.placeholder = "Player 1 name"
5151
player1Field.snp.makeConstraints { (maker: ConstraintMaker) in
@@ -56,7 +56,7 @@ class LoggedOutViewController: UIViewController {
5656

5757
let player2Field = UITextField()
5858
self.player2Field = player2Field
59-
player2Field.borderStyle = UITextBorderStyle.line
59+
player2Field.borderStyle = UITextField.BorderStyle.line
6060
view.addSubview(player2Field)
6161
player2Field.placeholder = "Player 2 name"
6262
player2Field.snp.makeConstraints { (maker: ConstraintMaker) in

Sample/MVC/TicTacToe/TicTacToe.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@
611611
PRODUCT_BUNDLE_IDENTIFIER = com.uber.needle.tictactoe.TicTacToe;
612612
PRODUCT_NAME = "$(TARGET_NAME)";
613613
PROVISIONING_PROFILE_SPECIFIER = "";
614-
SWIFT_VERSION = 4.0;
614+
SWIFT_VERSION = 5.0;
615615
TARGETED_DEVICE_FAMILY = "1,2";
616616
};
617617
name = Debug;
@@ -630,7 +630,7 @@
630630
PRODUCT_BUNDLE_IDENTIFIER = com.uber.needle.tictactoe.TicTacToe;
631631
PRODUCT_NAME = "$(TARGET_NAME)";
632632
PROVISIONING_PROFILE_SPECIFIER = "";
633-
SWIFT_VERSION = 4.0;
633+
SWIFT_VERSION = 5.0;
634634
TARGETED_DEVICE_FAMILY = "1,2";
635635
};
636636
name = Release;

Sample/Pluginized/TicTacToe/TicTacToe.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,7 @@
10771077
PRODUCT_BUNDLE_IDENTIFIER = com.uber.needle.tictactoe.TicTacToe;
10781078
PRODUCT_NAME = "$(TARGET_NAME)";
10791079
PROVISIONING_PROFILE_SPECIFIER = "";
1080-
SWIFT_VERSION = 4.0;
1080+
SWIFT_VERSION = 5.0;
10811081
TARGETED_DEVICE_FAMILY = "1,2";
10821082
};
10831083
name = Debug;
@@ -1097,7 +1097,7 @@
10971097
PRODUCT_BUNDLE_IDENTIFIER = com.uber.needle.tictactoe.TicTacToe;
10981098
PRODUCT_NAME = "$(TARGET_NAME)";
10991099
PROVISIONING_PROFILE_SPECIFIER = "";
1100-
SWIFT_VERSION = 4.0;
1100+
SWIFT_VERSION = 5.0;
11011101
TARGETED_DEVICE_FAMILY = "1,2";
11021102
};
11031103
name = Release;

Sample/Pluginized/TicTacToe/TicTacToeCore/AppDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
2222

2323
var window: UIWindow?
2424

25-
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
25+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
2626
registerProviderFactories()
2727

2828
let window = UIWindow(frame: UIScreen.main.bounds)

Sample/Pluginized/TicTacToe/TicTacToeCore/Game/GameViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class GameViewController: ObservableViewController, UICollectionViewDataSource,
111111

112112
private func showAlert(with title: String, completionHandler handler: @escaping () -> ()) {
113113
let alert = UIAlertController(title: title, message: nil, preferredStyle: .alert)
114-
let closeAction = UIAlertAction(title: "Close Game", style: UIAlertActionStyle.default) { _ in
114+
let closeAction = UIAlertAction(title: "Close Game", style: UIAlertAction.Style.default) { _ in
115115
handler()
116116
}
117117
alert.addAction(closeAction)

Sample/Pluginized/TicTacToe/TicTacToeCore/LoggedOut/LoggedOutViewController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class LoggedOutViewController: UIViewController {
4545
private func buildPlayerFields() -> (player1Field: UITextField, player2Field: UITextField) {
4646
let player1Field = UITextField()
4747
self.player1Field = player1Field
48-
player1Field.borderStyle = UITextBorderStyle.line
48+
player1Field.borderStyle = UITextField.BorderStyle.line
4949
view.addSubview(player1Field)
5050
player1Field.placeholder = "Player 1 name"
5151
player1Field.snp.makeConstraints { (maker: ConstraintMaker) in
@@ -56,7 +56,7 @@ class LoggedOutViewController: UIViewController {
5656

5757
let player2Field = UITextField()
5858
self.player2Field = player2Field
59-
player2Field.borderStyle = UITextBorderStyle.line
59+
player2Field.borderStyle = UITextField.BorderStyle.line
6060
view.addSubview(player2Field)
6161
player2Field.placeholder = "Player 2 name"
6262
player2Field.snp.makeConstraints { (maker: ConstraintMaker) in

Sources/NeedleFoundation/Component.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public protocol Scope: AnyObject {
3535
/// contains a set of properties it provides to units of its scope as well
3636
/// as child scopes. A component instantiates child components that define
3737
/// child scopes.
38+
@dynamicMemberLookup
3839
open class Component<DependencyType>: Scope {
3940

4041
/// The parent of this component.
@@ -95,6 +96,10 @@ open class Component<DependencyType>: Scope {
9596
return instance
9697
}
9798

99+
public subscript<T>(dynamicMember keyPath: KeyPath<DependencyType, T>) -> T {
100+
return dependency[keyPath: keyPath]
101+
}
102+
98103
// MARK: - Private
99104

100105
private let sharedInstanceLock = NSRecursiveLock()

0 commit comments

Comments
 (0)