一,判断类别 ==(isKindOfClass, isMemberOfClass)这两个函数了 被 is 替代
arrData = ["0","1","2","3","4","5","6","7","8","9","10"]
if arrData is Array<Any> {
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

// 原因就是没有处理错误 。我们根据错误提示,调用可以抛出,但它没有标记和错误处理通过加一个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
网友评论