在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
一、可选类型为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)”) } 二、Swift3.0把闭包的入参参数名去掉了
Function types cannot have argument labels; use '_' before 'respose'
三、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).
四、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?) {
}
五、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里就行了
|
请发表评论