Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 我想创建一个函数,它可以返回responseJson并使用它在init中创建一些对象_Swift - Fatal编程技术网

Swift 我想创建一个函数,它可以返回responseJson并使用它在init中创建一些对象

Swift 我想创建一个函数,它可以返回responseJson并使用它在init中创建一些对象,swift,Swift,我的患者类别是: import UIKit import Alamofire class ViewController: UIViewController { @IBOutlet weak var uiNameSearch: UITextField! @IBOutlet weak var uiGivenName: UITextField! override func viewDidLoad() { super.viewDidLoad() // Do any additional

我的患者类别是:

import UIKit
import Alamofire
class ViewController: UIViewController {

@IBOutlet weak var uiNameSearch: UITextField!
@IBOutlet weak var uiGivenName: UITextField!
override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
}

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


@IBAction func searchForName(sender: UIButton) {
    let header = ["Accept" : "application/json"]
   let name = uiNameSearch.text!
    let given = uiGivenName.text!
    Alamofire.request(.GET, "https://open-ic.epic.com/FHIR/api/FHIR/DSTU2/Patient?family=\(name)&given=\(given)", headers: header).responseJSON { response in
        let patient = response.result.value!
        if let entry = patient.objectForKey("entry") {
            if let link = entry[0].objectForKey("link") {
                if let url = link[0].objectForKey("url") {
                    let fullNameArr = url.componentsSeparatedByString("/")

                        print(fullNameArr[fullNameArr.count-1])

                }
                //print(link)
            }
        }






}
}
}

我想用init中的响应来创建对象,我该怎么做?

确切的问题是什么?我想创建一个这样的函数:alamofireResponse()->response{}来像对象一样返回响应,然后在initWhy
responseJson
的尖括号中使用它?是否要使用泛型?我需要一个函数来返回响应。我怎么做?我不太清楚你需要什么样的功能。你希望别人怎么称呼你。请将这些细节添加到问题中,否则人们将很难理解您需要什么。确切的问题是什么?我想创建一个这样的函数:alamofireResponse()->Response{}以像对象一样返回响应,然后在尖括号中的initWhy
responseJson
中使用它?是否要使用泛型?我需要一个函数来返回响应。我怎么做?我不太清楚你需要什么样的功能。你希望别人怎么称呼你。请在问题中添加这些细节,否则人们将难以理解您的需求。
class Patient {
    var name: String
    var given: String
    var id: String

init(name: String, given: String, id: String) {

}

}