Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Filip2Stojanovski
Copy link
Collaborator

Introducing a generic method that accepts the expected type explicitly and handles the type casting internally.

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) {
Copy link
Member

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 }
Copy link
Member

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants