1、可選類型爲nil,對可選類型強制解包crash
var response:String?
let dict = response! // 強制解包致使 crash
fatal error: unexpectedly found nil while unwrapping an Optional value
// 能夠使用下面的解包方式
if let dict = response {
print("----->\(dict)」)
}
2、Swift3.0把閉包的入參參數名去掉了
Function types cannot have argument labels; use '_' before 'respose'
3、Could not cast value of type 'UIView' (0x1b57b3ed8) to ‘XXX’
XXX 是本身定義的類名,出現這種問題 先檢查代碼,xib和代碼的類是否同樣,若是id什麼都是同樣的,那麼,直接將xib刪掉,從新添加就好了!
也有多是本身代碼問題,像下面這種將AddItemsTopView 改成UIView就好了
Could not cast value of type 'UIView' (0x1b57b3ed8) to 'ROMWESWIFT.AddItemsTopView' (0x100030ac8).
4、Argument of '#selector' refers to instance method 'btnClick(sender:)' that is not exposed to Objective-C
btn.addTarget(self, action:#selector(btnClick(sender:)), for: .touchUpInside) 報錯 Argument of '#selector' refers to instance method 'btnClick(sender:)' that is not exposed to Objective-C
func btnClick(sender:UIButton?) {
}
Selectors are a feature of Objective-C and can only be used with methods that are exposed to the dynamic Obj-C runtime. You can't have a selector to a pure Swift method.
If your class inherits from NSObject then its public methods are exposed to Obj-C automatically. Since your class does not inherit from NSObject you have to use the @objc attribute to indicate that you want this method exposed to Obj-C so that it may be called with an Obj-C selector.
#selector() is the new syntax in Swift 2.2. It allows the compiler to check that the selector you're trying to use actually exists. The old syntax is deprecated and will be removed in Swift 3.0.
加上 @objc 就行了
@objc func btnClick(sender:UIButton?) {
}
5、
nw_endpoint_flow_service_writes [2.1 192.168.10.129:8888 ready socket-flow (satisfied)] Write request has 4294967295 frame count, 0 byte count
使用 Alamofire 的GET請求,而後參數放到parars裏面會致使這個問題,把參數直接放到url裏就好了