4
2

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 3 years have passed since last update.

【Swift】Alamofire 5.2.1でModule 'Alamofire' has no member named 'request'と出る場合の対処法

Posted at

PodFileにpod 'Alertift'と指定し、最新版5.2.1を利用。

import UIKit
import Alamofire

class NetworkManagerEX: NSObject {

    func sendRequest(success: @escaping () -> Void) {
        let dic: Parameters = [
            "name1":"data1",
            "name2":"data2"
        ]
        Alamofire.request("http://localhost:8000/",
                          method: .post,
                          parameters: dic,
                          encoding: JSONEncoding.default)
            .responseJSON { response in
                switch response.result {
                case .success(let value):
                    print("VALUE:",value)
                    success()
                case .failure(let error):
                    print("RESPONSE ERROR:", error)
                }
        }
    }
}

上記内容でModule 'Alamofire' has no member named 'request'と怒られたので下記のように修正する事で回避しました。

    func sendRequest(success: @escaping () -> Void) {
        let dic: Parameters = [
            "name1":"data1",
            "name2":"data2"
        ]
        AF.request("http://localhost:8000/",
                          method: .post,
                          parameters: dic,
                          encoding: JSONEncoding.default)
            .responseJSON { response in
                switch response.result {
                case .success(let value):
                    print("VALUE:",value)
                    success()
                case .failure(let error):
                    print("RESPONSE ERROR:", error)
                }
        }
    }

###参考
StackOverView

4
2
1

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
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?