Swift语言特性整合

一,判断类别 ==(isKindOfClass, isMemberOfClass)这两个函数了 被 is 替代

        arrData = ["0","1","2","3","4","5","6","7","8","9","10"]
        if arrData is Array {
            print("是数组")
        }

二,便利字典

        let dic:Dictionary = ["key1":"val1", "key2":"val2", "key3":"val3", "key4":"val4"];
        for (key, value) in dic {
            print("key==\(key)")
            print("value==\(value)")
        }

三,移除所有子视图,无需循环只需要一句代码

        let none = self.view.subviews.map {
            $0.removeFromSuperview()
        }
        print(none)
或者
        for view in self.view.subviews {
            view.removeFromSuperview()
        }
或如果你正在寻找一个特定的类
        for view:UIView! in self.view.subviews {
            if (view != nil) {
                view.removeFromSuperview();
            }
        }

四,Call can throw, but it is not marked with 'try' and the error is not handled

1

// 原因就是没有处理错误 。我们根据错误提示,调用可以抛出,但它没有标记和错误处理通过加一个try解决。
// (PS: 就像Java中的异常错误处理,也是采用 try ...catch)

            do {
                try listenSocket.accept(onPort: UInt16(port))
            } catch let error as NSError {
                print("\(error.description)")
            }

@http://www.jianshu.com/p/b30d8f72e722

五,

六,

七,

八,

九,

十,

十一,

十二,

十三,

十,

十,

十,

十,

十,

十,

二十,

二十一,

二十二,

二十三,

二十四,

二十五,

二十六,

二十七,

二十八,

二十九,

三十,

你可能感兴趣的:(Swift语言特性整合)