LoginSignup
19
18

More than 5 years have passed since last update.

Swiftのnilがなるほどわからん

Posted at

Objective-Cのstr.length == 0のノリで、
Swiftでもカジュアルに空文字チェックをしてみたところ、どうしてこうなりました。

let str: NSString? = nil

str?.length == 0    // false
str?.length > 0     // false
str?.length < 0     // true

nil == 0    // false
nil > 0     // false
nil < 0     // true

さらに、

nil == true     // false
nil == false    // false

nilとはなんぞや。

19
18
5

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
19
18