diff --git a/ios/RIBs/Classes/DI/Component.swift b/ios/RIBs/Classes/DI/Component.swift index e889d45fe..66557d5f3 100644 --- a/ios/RIBs/Classes/DI/Component.swift +++ b/ios/RIBs/Classes/DI/Component.swift @@ -24,7 +24,7 @@ open class Component: Dependency { /// The dependency of this `Component`. - open let dependency: DependencyType + public let dependency: DependencyType /// Initializer. /// @@ -47,6 +47,14 @@ open class Component: Dependency { lock.unlock() } + #if swift(>=5.0) + + if let instance = sharedInstances[__function] as? T { + return instance + } + + #else + // Additional nil coalescing is needed to mitigate a Swift bug appearing in Xcode 10. // see https://bugs.swift.org/browse/SR-8704. // Without this measure, calling `shared` from a function that returns an optional type @@ -55,6 +63,8 @@ open class Component: Dependency { return instance } + #endif + let instance = factory() sharedInstances[__function] = instance