2015-07-20 44 views
1

我有這個布爾表達式,我要檢查在if語句:爲什麼我不能在if子句中使用這個布爾表達式?

var result : NSData? = getResult() 
var x : Bool = result == nil 

這工作得很好。

if x { 
} 

這不起作用

if result == nil { 
} 

它給我以下錯誤:

Type of expression is ambiguous without more context 
Brace block of statements is an unused closure 
Expected { after if condition 
Invalid character in source file 

我在做什麼錯?

+0

'if result == nil {}'does compile(if'result' is a optional)。問題必須在周圍環境中。 –

+0

你可以在問題中包含'result'的聲明嗎? –

+0

它不適合我! 「結果」是類型「NSData?」 – Traubenfuchs

回答

0

隱藏在if旁邊的隱形空白字符(不佔空格的字符)。

相關問題