0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

(初心者向け)Swift3.0で初アプリ - 外部サイトへアクセスしてみる - AlamoFire

Last updated at Posted at 2017-09-19

Swift3.0を使って簡単なiPhoneアプリを作ってみます
(初心者向け)Swift3.0で初アプリ - CocoaPods, Carthagoを使ってみるでAlamoFireを使えるようにしました

#1.AlamoFireを使ってみる
- 以下のようなコードを使ってAlamoFireを使ってみます
- ViewController.swiftに以下をコピペします

AlamoFireを使ってみる
import UIKit
import Alamofire
import SwiftyJSON

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        let urlJson = "https://ntp-a1.nict.go.jp/cgi-bin/json"
        let urlTime = "https://ntp-a1.nict.go.jp/cgi-bin/time"

        Alamofire.request(urlJson).responseJSON{ response in
            print(response)
        }
        
        Alamofire.request(urlTime).response{ response in
            print(response)
        }
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}


  • Simulatorで稼働させると、コンソールに下記のようにNICTから取得された時刻が表示されます
スクリーンショット 2017-09-19 12.18.47.png
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?