Github user shortstuffsushi commented on the pull request:
https://github.com/apache/cordova-plugin-file-transfer/pull/18#issuecomment-38276029
I don't know that I'd say the existing code is bad, or even wrong. Ternary
and coalescing operators are commonly used in Objective-C. There aren't really
any standards around the various Cordova repositories, so I don't think it's an
issue. In fact, your pull request here is using a variable that doesn't exist,
which wouldn't fix the problem either :(
The ultimate problem is that `[NSURL URLWithString:source]` returns an `id`
which Xcode is incorrectly attempting to cast to a `CGPathContext`, if I
remember correctly. That class does not have a `path` selector, and
consequently Xcode incorrectly assumes the line is invalid.
To fix this, you can use any of these chunks of code, depending on your
preference. They'll all work.
````
NSString *filePath = [source hasPrefix:@"/"] ? [source copy] : [(NSURL
*)[NSURL URLWithString:source] path];
````
````
NSString *filePath = [source hasPrefix:@"/"] ? [source copy] : [[NSURL
alloc] initWithString:source] path];
````
````
NSString *filePath;
if ([source hasPrefix:@"/"]) {
filePath = [source copy];
}
else {
filePath = [(NSURL *)[NSURL URLWithString:source] path];
// or
filePath = [[NSURL alloc] initWithString:source] path];
}
````
````
NSURL *url = [NSURL URLWithString:source]; // or [[NSURL alloc]
initWithString:source];
NSString *filePath = [url path];
````
@agrieve, could you choose one and pull it in to close this issue out,
please?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---