ios Swift Alamofire VS AFNetworking

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32988412/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 07:56:03  来源:igfitidea点击:

Swift Alamofire VS AFNetworking

iosswiftafnetworkingalamofire

提问by Puvanarajan

I am developing an app using Swift. I want to call a REST API. I found there are two popular libraries, AFNetworking and Alamofire. But I don't know which is better (is more popular or has more features).

我正在使用 Swift 开发一个应用程序。我想调用一个 REST API。我发现有两个流行的库,AFNetworking 和 Alamofire。但我不知道哪个更好(更受欢迎或具有更多功能)。

Can anybody suggest what are the main differences between Alamofire and AFNetworking?

有人可以建议 Alamofire 和 AFNetworking 之间的主要区别是什么吗?

回答by Arsen

Use AFNetworkingif you use Objective-C

使用AFNetworking如果您使用的Objective-C

Use Alamofireif you use Swift

使用Alamofire,如果你使用SWIFT

回答by Luke Berry

AFNetworkingand Alamofireare by the same people (the Alamofire Software Foundation), Alamofireis their Swift version whereas AFNetworkingis the Objective-C version.

AFNetworking并且Alamofire是由同一个人(Alamofire 软件基金会编写的Alamofire是他们的 Swift 版本,AFNetworking而是 Objective-C 版本。

Feature wise they are the same.

功能方面它们是相同的。

回答by Suraj Sonawane

If you are developing app using Objective-Cthen you must go with the AFNetworking.

如果您正在使用开发应用程序,Objective-C那么您必须使用AFNetworking。

Other wise if you are developing with the Swiftthen try the latest release of Alamofire.

其他明智的,如果你正在开发Swift然后尝试最新版本的Alamofire。

In both the libraries Networking is done asynchronously. Only difference is Alamofire is no longer supported on iOS 7 due to the lack of support for frameworks.

在这两个库中,网络都是异步完成的。唯一不同的是,由于缺乏对框架的支持,iOS 7 不再支持 Alamofire。

回答by ireshika piyumalie

AFNetworking:

AF网络:

  • This is the objective -C version of the library.
  • This is very powerful and you could install this in your Swift project and use it as a bridge to the swift project.
  • 这是库的目标 -C 版本。
  • 这非常强大,您可以将其安装在您的 Swift 项目中,并将其用作连接 Swift 项目的桥梁。

Alamofire:

阿拉莫火:

  • This is the Swift version of AFNetworking.
  • But not all the features of AFNetworking are included.
  • 这是 AFNetworking 的 Swift 版本。
  • 但并非 AFNetworking 的所有功能都包括在内。

If you are good at Objective-C use AFNetworking. If not, use Alamofire. It is simple and many resources are available for Swift.

如果您擅长 Objective-C,请使用 AFNetworking。如果没有,请使用 Alamofire。它很简单,并且有许多可用于 Swift 的资源。

回答by Amit Mishra

AFNetworkingis an Objective-C networking library for iOS, macOS and tvOS. It is a robust library that has been around for many years. From basic networking to advanced features such as Network Reachability and SSL Pinning, AFNetworking has it all. It is one of the most popular iOS libraries of all time with almost 50 million downloads.

AFNetworking是一个适用于 iOS、macOS 和 tvOS 的 Objective-C 网络库。它是一个强大的库,已经存在多年。从基本网络到高级功能(如网络可达性和 SSL 固定),AFNetworking 应有尽有。它是有史以来最受欢迎的 iOS 库之一,下载量接近 5000 万次。

Alamofireis AFNetworking's successor but is written in Swift. The two libraries share a similar feature set, with the main difference being the language in which they are written.

Alamofire是 AFNetworking 的继任者,但它是用 Swift 编写的。这两个库共享相似的功能集,主要区别在于编写它们的语言。

If you are starting a brand new Swift project, my recommendation is to use Alamofire so that your core networking library is consistent with your own source code. Otherwise, both AFNetworking and Alamofire are great options.

如果您正在开始一个全新的 Swift 项目,我的建议是使用 Alamofire,以便您的核心网络库与您自己的源代码保持一致。否则,AFNetworking 和 Alamofire 都是不错的选择。

Source : Raywenderlich

来源 : Raywenderlich