LoginSignup
39
39

More than 5 years have passed since last update.

SwiftでAFNetworking

Posted at

適宜インクルードした後

AF.swift
let manager = AFHTTPRequestOperationManager()
manager.GET("http://google.com/", parameters: nil, success: { (operation: AFHTTPRequestOperation!, responseObject: AnyObject!) in
    println(responseObject)
}, failure: { (operation: AFHTTPRequestOperation!, error: NSError!) in
    println(error.localizedDescription)
})

あんまり変わりません
ブロックの書き方はカッコ良くなりました。
引数の間に,があるのがいいですね。なんとなくRubyっぽい。

参考:Objective-Cでは

AF.m
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager GET:@"http://example.com/resources.json" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Error: %@", error);
}];
39
39
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
39
39