Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSURL "missing argument for parameter in call" Swift

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?

like image 785
simge Avatar asked Nov 23 '25 19:11

simge


1 Answers

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

like image 115
Ali Abbas Avatar answered Nov 25 '25 10:11

Ali Abbas