-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
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
Simplify adding requirements #51
base: master
Are you sure you want to change the base?
Conversation
This method is designed for Objective-C compatibility and uses runtime type checking (`isKindOfClass:`) to validate the value. | ||
*/ | ||
@objc(addRequirementWithKey:ofType:requirementCheck:) | ||
public func addRequirementWithKey(key: String, ofType type: AnyClass, requirementCheck: @escaping (Any) -> Bool) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we also add unavailable for swift flag, the last time I did it, i think it was adding __ to the function name, but there might be be a better option now.
@objc(addRequirementWithKey:ofType:requirementCheck:) | ||
public func addRequirementWithKey(key: String, ofType type: AnyClass, requirementCheck: @escaping (Any) -> Bool) { | ||
userRequirements.updateValue({ value in | ||
guard let value = value as? NSObject, value.isKind(of: type) else { return false } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of returning false
if the type does not match, maybe we could throw an error? That way, the user would know something went wrong instead of just getting a false negative response. What do you think about that approach?
Introducing a generic method that accepts the expected type explicitly and handles the type casting internally.