var dict = [Int:Any]()
dict[1] = 15

let x = dict[1] as? String
print(x) // nil because dict[1] is an Int

let zz = dict[1] as! String // crashes because a forced downcast fails


dict[2] = "Yo"

let z = dict[2] as! String?
print(z) // optional("Yo")
let z2 = dict[2] as! String
print(z2) // exactly String


let m = dict[3] as! String?
print(m) // nil. the forced downcast succeeds, but dict[3] has no value

警告 Treating a forced downcast to ‘NSNumber’ as optional will never produce ‘nil’
提示 Fix-it use ‘as?’ to perform a conditional downcast to ‘NSNumber’

Read more »

最近用 swfit 需要一个 barbuttonitem,在 storyboard 创建后 connect 到 viewcontroller 发现,在 viewdidload 里还有值,被隐藏然后再次加载的时候为 nil。

From a practical perspective, in iOS and OS X outlets should be defined as declared properties. Outlets should generally be weak, except for those from File’s Owner to top-level objects in a nib file (or, in iOS, a storyboard scene) which should be strong. Outlets that you create should therefore typically be weak, because:

Outlets that you create to subviews of a view controller’s view or a window controller’s window, for example, are arbitrary references between objects that do not imply ownership.
The strong outlets are frequently specified by framework classes (for example, UIViewController’s view outlet, or NSWindowController’swindow outlet).

Read more »

Jade官网 Node Template Engine,自己来看就是简便 html 标签语言的一种实现。对了现在改名叫做 pug 了。

这个语法还是有点不习惯,尤其是分支感觉很凌乱。

Read more »

女朋友的设计

算是多年后再一次的hello world,上次是毕业后用的wordpress,现在帐号都找不到了,这次用了hexo和github,我想自己的记录再也不会丢了。

Read more »
0%