| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
jopen
8年前发布

N3Restful-Swift - RESTful service interaction in iOS project with Swift

N3Restful-Swift

RESTful service interaction in Swift iOS project.

Features

  • Request with dictionary param.
  • Request with object param RESTParam.
  • Request with multipart data (JSON, String, File).

Requirements

  • iOS 8.0 or later.

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To integrate Alamofire and SwiftyJSON into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'  platform :ios, '8.0'  use_frameworks!    pod 'Alamofire'  pod 'SwiftyJSON'

Then, run the following command:

$ pod install

Manually

If you prefer not to use either of the aforementioned dependency managers, you can integrate Alamofire and SwwiftyJSON into your project manually.

Usage

Create data model SignInResult

class SignInResult: ROJSONObject {      var access_token: String! {          return Value<String>.get(self, key: "access_token")      }        lazy var user: User! = {          return Value<User>.getROJSONOject(self, key: "user")      }()  }
class User: ROJSONObject {        var email: String! {          return Value<String>.get(self, key: "email")      }        var first_name: String! {          return Value<String>.get(self, key: "first_name")      }        var last_name: String! {          return Value<String>.get(self, key: "last_name")      }  }

Create object param class

class SignInParam: RESTParam {      var email: String!      var password: String!  }

Invoker

  • Init invoker with a controller:
init() {      super.init(controllerName: "sessions")  }
  • Make a request to sign in and parse response to SignInResult object
func signIn(param: SignInParam, completion: (result: SignInResult?, error: RESTError?) -> Void) {      let request = requestWithMethodName(nil)        request.POST(param) { (result: SignInResult?, error) -> () in          completion(result: result, error: error)      }  }

Contribution

If you see any problems or you want to make an improvement, please create Issues ans we can discuss.

Thanks

项目地址: https://github.com/nguyenngocnhan90/N3Restful-Swift

 本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
 转载本站原创文章,请注明出处,并保留原始链接、图片水印。
 本站是一个以用户分享为主的开源技术平台,欢迎各类分享!
 本文地址:https://www.open-open.com/lib/view/open1456839896593.html
Apple Swift开发 N3Restful-Swift