热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

使用iOS8的Swift3中的Alamofire-AlamofireinSwift3withiOS8

IveupdatedtothelatestversionofXcode(8)andafterupgradingthecodetoSwift3,Alamofires

I've updated to the latest version of Xcode (8) and after upgrading the code to Swift 3, Alamofire suddenly stops working and throwing a lot of errors.

我已经更新到最新版本的Xcode(8),在将代码升级到Swift 3之后,Alamofire突然停止工作并抛出了很多错误。

After a lot of research, I find that Alamofire for Swift 3 is compatible with iOS9+, so now I have to find another one that works with iOS8+.

经过大量的研究,我发现Alamofire for Swift 3与iOS9 +兼容,所以现在我必须找到另一个适用于iOS8 +的版本。

Do you know how can I make the same functionality as Alamofire for iOS8?

你知道我怎样才能为iOS8的Alamofire提供相同的功能?

2 个解决方案

#1


3  

try this fork, https://github.com/tonyli508/AlamofireDomain

试试这个分支,https://github.com/tonyli508/AlamofireDomain

or pod directly:

或直接:

pod 'AlamofireDomain', '~> 4.0'

pod'AlamofireDomain','〜> 4.0'

#2


2  

I didn't find a "real" alternative to Alamofire for iOS 8, so I tried using the URLRequest from Apple's Swift itself.

我没有为iOS 8找到Alamofire的“真正”替代品,所以我尝试使用Apple的Swift本身的URLRequest。

So here is the example I finally got after trying and trying (even without SwiftyJSON):

所以这是我在尝试和尝试后最终得到的例子(即使没有SwiftyJSON):

func searchPosts() -> [Post] {
    var request = URLRequest(url: URL(string: "https://www.mywebsite.com/searchPosts.php")!)
    request.httpMethod = "POST"
    let postString = ""
    request.httpBody = postString.data(using: .utf8)
    request.addValue("application/json", forHTTPHeaderField: "Content-Type")
    request.addValue("application/json", forHTTPHeaderField: "Accept")

    let task = URLSession.shared.dataTask(with: request) { data, response, error in

        if let httpStatus = response as? HTTPURLResponse, httpStatus.statusCode != 200 {
            print(httpStatus.statusCode)
            self.showError()
        } else {
            do {
                self.listPosts = [Post]()
                // Convert NSData to Dictionary where keys are of type String, and values are of any type
                let json = try JSONSerialization.jsonObject(with: data!, options: JSONSerialization.ReadingOptions.mutableContainers) as! [String:AnyObject]

                for field in json["posts"] as? [AnyObject] ?? [] {

                    // Create "Post" object
                    let post = Post(
                        id: (field["id"])! as! String,
                        title: (field["title"] as! String),
                        alias: (field["alias"] as! String),
                        catid: (field["catid"] as! String),
                        catname: (field["catname"] as! String),
                        date: (field["date"] as! String),
                        image: (field["image"] as! String),
                        introtext: (field["introtext"] as! String),
                        fulltext: (field["fulltext"] as! String)
                    )
                    self.listPosts.append(post)
                }

                DispatchQueue.main.async {
                    self.tableView.reloadData()
                }
            } catch {
                self.showError()
            }
        }
    }

    task.resume()

    return listPosts
}

I hope it could help other developers. I will be much appreciated if someone found another possible solution to this problem.

我希望它可以帮助其他开发人员。如果有人找到另一个可能解决这个问题的方法,我将不胜感激。

Regards


推荐阅读
  • 探讨如何真正掌握Java EE,包括所需技能、工具和实践经验。资深软件教学总监李刚分享了对毕业生简历中常见问题的看法,并提供了详尽的标准。 ... [详细]
  • Android 渐变圆环加载控件实现
    本文介绍了如何在 Android 中创建一个自定义的渐变圆环加载控件,该控件已在多个知名应用中使用。我们将详细探讨其工作原理和实现方法。 ... [详细]
  • Explore how Matterverse is redefining the metaverse experience, creating immersive and meaningful virtual environments that foster genuine connections and economic opportunities. ... [详细]
  • 深入解析Android自定义View面试题
    本文探讨了Android Launcher开发中自定义View的重要性,并通过一道经典的面试题,帮助开发者更好地理解自定义View的实现细节。文章不仅涵盖了基础知识,还提供了实际操作建议。 ... [详细]
  • Explore a common issue encountered when implementing an OAuth 1.0a API, specifically the inability to encode null objects and how to resolve it. ... [详细]
  • 本文详细介绍了如何使用 Yii2 的 GridView 组件在列表页面实现数据的直接编辑功能。通过具体的代码示例和步骤,帮助开发者快速掌握这一实用技巧。 ... [详细]
  • 使用 Azure Service Principal 和 Microsoft Graph API 获取 AAD 用户列表
    本文介绍了一段通用代码示例,该代码不仅能够操作 Azure Active Directory (AAD),还可以通过 Azure Service Principal 的授权访问和管理 Azure 订阅资源。Azure 的架构可以分为两个层级:AAD 和 Subscription。 ... [详细]
  • 本文详细介绍了Java编程语言中的核心概念和常见面试问题,包括集合类、数据结构、线程处理、Java虚拟机(JVM)、HTTP协议以及Git操作等方面的内容。通过深入分析每个主题,帮助读者更好地理解Java的关键特性和最佳实践。 ... [详细]
  • 扫描线三巨头 hdu1928hdu 1255  hdu 1542 [POJ 1151]
    学习链接:http:blog.csdn.netlwt36articledetails48908031学习扫描线主要学习的是一种扫描的思想,后期可以求解很 ... [详细]
  • This document outlines the recommended naming conventions for HTML attributes in Fast Components, focusing on readability and consistency with existing standards. ... [详细]
  • 在macOS环境下使用Electron Builder进行应用打包时遇到签名验证失败的问题,具体表现为签名后spctl命令检测到应用程序未通过公证(Notarization)。本文将详细探讨该问题的原因及解决方案。 ... [详细]
  • 本文深入探讨了 Java 中的 Serializable 接口,解释了其实现机制、用途及注意事项,帮助开发者更好地理解和使用序列化功能。 ... [详细]
  • 本文总结了在使用Ionic 5进行Android平台APK打包时遇到的问题,特别是针对QRScanner插件的改造。通过详细分析和提供具体的解决方法,帮助开发者顺利打包并优化应用性能。 ... [详细]
  • 本章将深入探讨移动 UI 设计的核心原则,帮助开发者构建简洁、高效且用户友好的界面。通过学习设计规则和用户体验优化技巧,您将能够创建出既美观又实用的移动应用。 ... [详细]
  • MySQL 数据库迁移指南:从本地到远程及磁盘间迁移
    本文详细介绍了如何在不同场景下进行 MySQL 数据库的迁移,包括从一个硬盘迁移到另一个硬盘、从一台计算机迁移到另一台计算机,以及解决迁移过程中可能遇到的问题。 ... [详细]
author-avatar
凡秘能
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有