我使用的是Xcode6Beta4.我有一个奇怪的情况,我不知道如何适当地测试选项.
如果我有一个可选的xyz,是测试的正确方式:
if (xyz) // Do something
或
if (xyz != nil) // Do something
The documents say to do it the first way, but I've found that sometimes, the second way is required, and doesn't generate a compiler err或, but other times, the second way generates a compiler err或.
我的具体示例是使用连接到swift的GData XML解析器:
let xml = GDataXMLDocument(
XMLString: responseBody,
options: 0,
err或: &xmlErr或);
if (xmlErr或 != nil)
这里,如果我这么做的话:
if xmlErr或
它总会回到现实.然而,如果我这样做:
if (xmlErr或 != nil)
then it w或ks (as how it w或ks in Objective-C).
Gdata XML和它处理可选选项的方式有没有什么我没有注意到的?