We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hi! I get in line 66 this warning: "Operator should no longer be declared with body; use a precedence group instead".
How to fix it?
The text was updated successfully, but these errors were encountered:
@iOS-altima
Quick but not tested update for Swift 3. It also does not support any way to release the instances. You could implement it yourself ;)
public protocol Instantiatable { init() } fileprivate var instances = [String: Instantiatable]() infix operator <~ extension Instantiatable { public static var shared: Self { return set { $0 } } public static func set(with setter: (Self) -> Self) -> Self { guard let instance = instances["\(self)"] as? Self else { return setInstance(self.init(), with: setter, overridable: true) } return setInstance(instance, with: setter, overridable: false) } private static func setInstance(_ instance: Self, with setter: (Self) -> Self, overridable: Bool) -> Self { let instance = restoreInstanceIfNeeded(instance1: instance, instance2: setter(instance), overridable: overridable) instances["\(self)"] = instance return instance } private static func restoreInstanceIfNeeded(instance1 i1: Self, instance2 i2: Self, overridable: Bool) -> Self { guard type(of: i1) is AnyClass else { return i2 } return ((i1 as AnyObject) !== (i2 as AnyObject)) && !overridable ? i1 : i2 } } extension Instantiatable { public static var instance: Self.Type { return self } @discardableResult public static func <~ (type: Self.Type, newInstance: Self) -> Self { return type.set { _ in newInstance } } }
Sorry, something went wrong.
No branches or pull requests
Hi!
I get in line 66 this warning: "Operator should no longer be declared with body; use a precedence group instead".
How to fix it?
The text was updated successfully, but these errors were encountered: