NSURL "missing argument for parameter in call" Swift
I am using obj-c and swift classes together. And in one swift class I am trying to convert objective c code to swift. However, I have a problem with NSURL.
source:
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@://", appItem.URLSchema]];
and URLSchema is declared in the header file like this:
@property (nonatomic, copy) NSString *URLSchema;
I am converting the object code c above to quickly:
var url: NSURL = NSURL(string:"%@://",relativeToURL: appItem.URLSchema)
but it says "missing argument for parameter" path "in the call
when i try this:
var url: NSURL = NSURL.URLWithString("%@://", appItem.URLSchema)
it specifies an additional argument in the call.
what do you suggest to convert correctly?
source to share
Second argument: RelativeToURL
is of type NSURL
and you are passing a string
Try the following:
var url:NSURL = NSURL(string: "\(appItem.URLSchema)://")
For more information, you can see the "String interpolation" section in the "Swift program langage" iBook .
String interpolation is a way of constructing a new String value from a combination of constants, variables, literals, and expressions by enclosing their value inside a string literal. Every element you insert into a string literal is wrapped in a pair of parentheses, prefixed with a backslash
source to share