-
Notifications
You must be signed in to change notification settings - Fork 281
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
[GTRepository shouldFileBeIgnored:success:error:] cannot be used from Swift #541
Comments
I suggest |
Well that's annoying 😞 I think I prefer |
👍 for Josh's proposal |
I've been giving this some thought, and since the primary reason to introduce a new method at all is for use in Swift there's another pattern that might make sense:
Or alternately use an enum:
The logic behind this approach is that the success and ignored flags are mutually exclusive, so there's no particular downside to collapsing them into a single return value (although the current method defaults to claiming a file should be ignored if the call to Plus it removes any question of deprecating the original method, since it would simply be a wrapper that allows slightly different access to the same information. |
I like that a lot 👍 But why would we remove the error parameter? |
Error parameters make Swift code quite verbose because the bridge automatically strips out the NSError parameter and gives the method the
|
Sure, but then you lose any error information. While I agree that Also, I haven't used Swift much, but couldn't you just do: let shouldIgnore = try? repo.shouldIgnoreFileURL(file) Granted, then you're dealing with an optional, but it's a little less cumbersome. |
Nice, I hadn't come across the However, it's apparently the end of my work day and my brain has died, because now that I look at this particular method what actually happens if there's an error parameter is that the bridge cannot translate it (since the return value's not a BOOL or nullable object), and so it comes across to Swift with a signature like this:
Not inherently good or bad, as the end result is that you can grab the NSError if you want it or pass nil if you don't (plus there's at least one other method that I've come across in Objective-Git that doesn't bridge with a Lastly, any preference for enum vs. NSInteger return? I'm currently using the enum in testing simply because then my code is more self-documenting, but it does introduce yet another one-off enum to the codebase. |
Ha, well, that's a bummer.
👍 enum. |
This is actually a general problem that affects a few different methods throughout the codebase. The problem is that Swift assumes that the BOOL return value indicates success or failure, and as a result it is impossible to get the return value for this method (and others like it). In order to fix this it would need to be revised to something along these lines (hopefully with better naming):
I'm happy to revise methods that have this problem as I run into them and submit pull requests, but I wasn't sure what would be the best method for handling the change, since it's nowhere near backwards compatible (add a deprecated message for the original method? Just leave it alone and add a wrapper that will work properly in Swift? Also, how should I revise the method name, since I'm not too happy with the pattern that I used above?).
Thoughts?
The text was updated successfully, but these errors were encountered: