I use obj-c and swift classes together. And at one swift class, I try to convert objective c code to swift. However, I have a problem about NSURL.
the original code is:
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@://", appItem.URLSchema]];
and URLSchema is declared in the header file like this:
@property (nonatomic, copy) NSString *URLSchema;
I convert the objective c code which is above to swift:
var url: NSURL = NSURL(string:"%@://",relativeToURL: appItem.URLSchema)
but it says "missing argument for parameter "path" in call"
when I try this:
var url: NSURL = NSURL.URLWithString("%@://", appItem.URLSchema)
it says extra argument in call.
what do you suggest to convert it properly?
The second argument : RelativeToURL has the type NSURL and you pass a String
Try this :
var url:NSURL = NSURL(string: "\(appItem.URLSchema)://")
For more informations, you can take a look on the 'String Interpolation' section in the "Swift programming langage" iBook.
String interpolation is a way to construct a new String value from a mix of constants, variables, literals, and expressions by including their values inside a string literal. Each item that you insert into the string literal is wrapped in a pair of parentheses, prefixed by a backslash
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With