小编Ujj*_*ani的帖子

如何向dataTaskWithUrl添加标头?

我有一个dataTaskWithUrl:

        var headers: NSDictionary = ["X-Mashape-Key": "my-secret-key" , "Accept" : "application/json"]
        var stringUrl = "https://restcountries-v1.p.mashape.com/all"
        stringUrl = stringUrl.stringByReplacingOccurrencesOfString(" ", withString: "+")
        let url = NSURL(string: stringUrl)
        let session = NSURLSession.sharedSession()
        let task = session.dataTaskWithURL(url!, completionHandler: { (data, response, error) -> Void in

        if let jsonResult = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: nil) as? NSDictionary{

           println(jsonResult)

        }else{
            println("error")
        }

      })

       task.resume()
Run Code Online (Sandbox Code Playgroud)

我想在我的任务中添加标题.

换句话说,我想将此代码转换为swift:

NSDictionary *headers = @{@"X-Mashape-Key": @"my-secret-key", @"Accept": @"application/json"};
UNIUrlConnection *asyncConnection = [[UNIRest get:^(UNISimpleRequest *request) {
  [request setUrl:@"https://restcountries-v1.p.mashape.com/all"];
  [request …
Run Code Online (Sandbox Code Playgroud)

json ios swift

14
推荐指数
2
解决办法
1万
查看次数

如何在UITableViewCells之间添加间距 - Swift

我有一个表有一些自定义.

我的tableView的照片

这是我的代码:

import UIKit

class ViewController: UIViewController, UITableViewDelegate {
    var exercises : [String] = ["Swimming", "Running", "Weight Lifting", "Biking", "Climbing"]

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view, typically from a nib.
    }

    //Necessary for basic tableView setup. Defines number of rows in a specific section.
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
        //Setting the amount of rows to the number of elements in exercises. This function returns that.
        tableView.backgroundColor = UIColor.clearColor()
        return …
Run Code Online (Sandbox Code Playgroud)

uitableview ios swift

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

ios ×2

swift ×2

json ×1

uitableview ×1