[英]NSURL “missing argument for parameter in call” Swift
I use obj-c and swift classes together. 我一起使用obj-c和swift类。 And at one swift class, I try to convert objective c code to swift.
在一个快速的课程中,我尝试将客观的c代码转换为swift。 However, I have a problem about NSURL.
但是,我有一个关于NSURL的问题。
the original code is: 原始代码是:
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@://", appItem.URLSchema]];
and URLSchema is declared in the header file like this: 和URLSchema在头文件中声明如下:
@property (nonatomic, copy) NSString *URLSchema;
I convert the objective c code which is above to swift: 我将上面的目标c代码转换为swift:
var url: NSURL = NSURL(string:"%@://",relativeToURL: appItem.URLSchema)
but it says "missing argument for parameter "path" in call" 但它说“在调用中缺少参数”path“的参数”
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 第二个参数:
RelativeToURL
的类型为NSURL
,您传递一个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 . 有关更多信息,您可以查看“Swift编程语言” 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.
字符串插值是一种通过在字符串文字中包含它们的值,从混合的常量,变量,文字和表达式构造新的String值的方法。 Each item that you insert into the string literal is wrapped in a pair of parentheses, prefixed by a backslash
插入到字符串文字中的每个项目都包含在一对括号中,前缀为反斜杠
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.