- 拿到当前类名
let className = String(describing: type(of: self))
- swift3.0之后
NSNotification name
已经修改成NSNotification.Name
结构体了,建议定义的时候直接定义为常量static let kUpdateUserInfo = NSNotification.Name("kUpdateUserInfo")
- Alamofire上传图片同时携带参数
func uploadfile(_ url :String,par :Dictionary<String,Any>? = nil,filedata :Data? = nil,fileName :String = "iamge.png", call :NetWorkFinishCall?){
Alamofire.upload(multipartFormData: { (MultipartFormData) in
if filedata != nil{
MultipartFormData.append(filedata!, withName: "file", fileName: fileName, mimeType: "image/png");
}
if par != nil{
for (key,value) in par!{
MultipartFormData.append((value as! String).data(using: .utf8)!, withName: key)
}
}
}, to:NetWorkTool.shareInstance.BaseUrl! + APPDefine.APIDefine.register) { (result) in
switch result{
case .success(let upload,_,_):
upload.responseJSON(completionHandler: { (data) in
if let block = call{
if let error = data.error{
}
let jsonObj = JSON(data:data.data!)
block((data.error == nil),jsonObj,data.error)
}
})
break
case .failure(let error):
if let block = call{
block(false,nil,error)
}
break
}
}
}
-
private(set) var a :String!;
修饰为对外只读对内可读可写。
- 定义接口的时候方法定义尽量考虑使用
mutating
修饰,以保证该方法在struce
和enum
中能够修改自己的变量;mutating
对class
是无效的。
网友评论