• iOS Swift开发的一些坑


          0、人难招,特别是对于没钱的小团队,大多数的iOS开发者没有Swift经验,有经验的也并不是很深入

          0.1、语言unwrap坑,虽然有自动修正提示,但感觉代码过程不流畅。 

          1、Realm的缺憾: 最近filter用得多,发现realm的一个真正的毛病,其查询语法关键字和结构和常规标准SQL完全不一致,这真是shit,必须认真看filter部分的文档并多次尝试才能找到真正正确的查询语句结构

         2、UIButton的远程图像获取的坑,尝试了很多种方法,最后发现得给他预设一个图像,远程图像加载才能成功,真是一个好坑啊,Android里面好像也见过类似问题。

         3、Alamosfire的文件上传,参考:https://stackoverflow.com/questions/26121827/uploading-file-with-parameters-using-alamofire

    1. // import Alamofire  
    2. func uploadWithAlamofire() {  
    3.   let image = UIImage(named: "bodrum")!  
    4.   
    5.   // define parameters  
    6.   let parameters = [  
    7.     "hometown": "yalikavak",  
    8.     "living": "istanbul"  
    9.   ]  
    10.   
    11.   Alamofire.upload(multipartFormData: { multipartFormData in  
    12.     if let imageData = UIImageJPEGRepresentation(image, 1) {  
    13.       multipartFormData.append(imageData, withName: "file", fileName: "file.png", mimeType: "image/png")  
    14.     }  
    15.   
    16.     for (key, value) in parameters {  
    17.       multipartFormData.append((value?.data(using: .utf8))!, withName: key)  
    18.     }}, to: "upload_url", method: .post, headers: ["Authorization": "auth_token"],  
    19.         encodingCompletion: { encodingResult in  
    20.           switch encodingResult {  
    21.           case .success(let upload, _, _):  
    22.             upload.response { [weak self] response in  
    23.               guard let strongSelf = self else {  
    24.                 return  
    25.               }  
    26.               debugPrint(response)  
    27.             }  
    28.           case .failure(let encodingError):  
    29.             print("error:(encodingError)")  
    30.           }  
    31.   })  
    32. }  

        4、NavigationViewController的TabBarViewController的内嵌ViewController设置其NavigationButtionItem,请注意,这种情况是因为TabBarVC是NavigationVC的栈顶VC,所以操作它的NavagationItem

    1. let b = UIBarButtonItem( image:#imageLiteral(resourceName: "post_message"), style:.plain, target:self, action:#selector(CommunityViewController.postClick(_:)))  
    2.      
    3.   
    4. elf.tabBarController?.navigationItem.rightBarButtonItem = b  



  • 相关阅读:
    Sending post
    <<the not so short introduction to Latex2e >> 读书笔记
    Latex 书签中文乱码解决方案
    VisualSVN迁移到其他服务器 子曰
    C#遍历DataSet中数据的几种方法总结 子曰
    Extjs formpanel加载数据的两种方式 子曰
    向老销售取经,学来的一点软件销售技巧 子曰
    extjs 实现 NumberField 即时计算 子曰
    Ext.form.DateField简单用法及日期范围控制 子曰
    解决.aspx中插入浮动广告不滚动问题 子曰
  • 原文地址:https://www.cnblogs.com/dhcn/p/7131095.html
Copyright © 2020-2023  润新知