Ios 下载数据并显示它

Ios 下载数据并显示它,ios,iphone,arrays,swift,uitableview,Ios,Iphone,Arrays,Swift,Uitableview,我正在用swift 2开发一个应用程序,但我有点卡住了。我有一个可靠的程序,它接受一个唯一的标识符并得到一个名称作为回报,所有的名称都存储在一个数组中。当我运行代码时,我会看到打印出来的名称,但当名称下载时,我有时会在控制台中多次遇到相同的错误,然后名称下载继续进行。此外,并非所有数组内容都显示在TableView中。 这是控制台中的错误: 导致发动机损坏和奇怪的碰撞。这将导致 未来版本中的异常。 堆栈:( 0 CoreFoundation 0x00000001051d79b5例外预处理+165

我正在用swift 2开发一个应用程序,但我有点卡住了。我有一个可靠的程序,它接受一个唯一的标识符并得到一个名称作为回报,所有的名称都存储在一个数组中。当我运行代码时,我会看到打印出来的名称,但当名称下载时,我有时会在控制台中多次遇到相同的错误,然后名称下载继续进行。此外,并非所有数组内容都显示在TableView中。 这是控制台中的错误:

导致发动机损坏和奇怪的碰撞。这将导致 未来版本中的异常。 堆栈:( 0 CoreFoundation 0x00000001051d79b5例外预处理+165 1 libobjc.A.dylib 0x0000000106dd6deb objc_异常_抛出+48 2 CoreFoundation 0x00000001051d78ed+[N异常提升:格式:][205 3基金会0x000 000 01057A3F5,AsjtAutoLayOuton MethTueRead仅79 4基金会0x000 000 01055 ab23 e - [ NSISEngulee的行为:PrimultExp修改:] + 31 5 UIKit 0x0000000105a916e0-[UIView(层次结构)\u postMovedFromSuperview:+575 6 UIKit 0x0000000105a9e3e2-[UIView(内部)\ U addSubview:定位:相对位置:][1967 7 UIKit 0x0000000105b16a54-[UITableView\u addContentSubview:atBack:+420 8 UIKit 0x0000000105b34fef\uuuu 53-[UITableView\uConfigureCellForDisplay:forIndexPath:]\uBlock\uInvoke+2679 9 UIKit 0x0000000105a97548+[UIView(动画)性能无动画:+65 10 UIKit 0x0000000105b3455f-[UITableView\u配置CellForDisplay:forIndexPath:+475 11 UIKit 0x0000000105b3f0f4-[UITableView\u createPreparedCellForGlobalRow:withIndexPath:willDisplay:+828 12 UIKit 0x0000000105b3f1db-[UITableView\u createPreparedCellForGlobalRow:将显示:][74 13 UIKit 0x0000000105b15250-[UITableView\u updateVisibleCellsNow:isRecursive:+3187 14 UIKit 0x0000000105b47fa8-[UITableView\u性能与CachedTraitCollection:+92 15 UIKit 0x0000000105b30599-[UITableView布局子视图]+218 16 UIKit 0x0000000105aa1a3b-[UIView(CALayerDelegate)布局层的子层:+710 17夸脱核心0x0000000109e5636a-[加莱尔布局子层]+146 18夸脱核心0x0000000109e4abd0(如果需要)分层布局交易+366 19 QuartzCore 0x0000000109e4aa4e\u ZN2CA58层布局和显示(如果需要)PNS\u 11事务+24 20夸脱核心0x0000000109e3f1d5_ZN2CA7Context18提交交易PNS_11交易+277 21夸脱核心0x0000000109e6c9f0_Zn2Ca11交易承诺+508 22夸脱芯0x0000000109e6ccd4_ZN2CA11Transaction14释放_螺纹EPV+224 23 libsystem_pthread.dylib 0x0000000107c0a39c_pthread_tsd_cleanup+470 24 libsystem_pthread.dylib 0x0000000107c09f78_pthread_exit+117 25 libsystem_pthread.dylib 0x0000000107c08596 pthread_attr_getschedpolicy+0 26 libsystem_pthread.dylib 0x0000000107c06375 start_wqthread+13 ) 2015-09-10 17:26:33.942 ProfileViewer[1130:82460]此应用程序正在从后台线程修改autolayout引擎,它可以 导致发动机损坏和奇怪的碰撞。这将导致 未来版本中的异常。 堆栈:( 0 CoreFoundation 0x00000001051d79b5例外预处理+165 1 libobjc.A.dylib 0x0000000106dd6deb objc_异常_抛出+48 2 CoreFoundation 0x00000001051d78ed+[N异常提升:格式:][205 3基金会0x000 000 01057A3F5,AsjtAutoLayOuton MethTueRead仅79 4基金会0x000 000 01055 AAA52 - [ NSISEngEngress优化] + 49 5基金会0x000 000 01055 AB314- [ NSISEngulee附带行为:PrimultExp修改:] + 245 6 UIKit 0x0000000105a916e0-[UIView(层次结构)\u postMovedFromSuperview:+575 7 UIKit 0x0000000105a9e3e2-[UIView(内部)\ U addSubview:定位:相对位置:][1967 8 UIKit 0x0000000105b16a54-[UITableView\u addContentSubview:atBack:+420 9 UIKit 0x0000000105b34fef\uuuu 53-[UITableView\uConfigureCellForDisplay:forIndexPath:]\uBlock\uInvoke+2679 10 UIKit 0x0000000105a97548+[UIView(动画)性能无动画:+65 11 UIKit 0x0000000105b3455f-[UITableView\u配置CellForDisplay:forIndexPath:+475 12 UIKit 0x0000000105b3f0f4-[UITableView\u createPreparedCellForGlobalRow:withIndexPath:willDisplay:+828 13 UIKit 0x0000000105b3f1db-[UITableView\u createPreparedCellForGlobalRow:将显示:][74 14 UIKit 0x0000000105b15250-[UITableView\u updateVisibleCellsNow:isRecursive:+3187 15 UIKit 0x0000000105b47fa8-[UITableView\u性能与CachedTraitCollection:+92 16 UIKit 0x0000000105b30599-[UITableView布局子视图]+218 17 UIKit
`Marthe Tordeur
Jorn Christiaens
Yarne Leuckx
Jordi Stevens
Jonathan Essende
Hanne Pappaert
Bert Van den Abbeele
Cedric de Smedt
Hanne Delcourt
2015-09-10 17:26:33.934 ProfileViewer[1130:82460] This application is modifying the autolayout engine from a background thread, which can
func fetchTitle(identifier: String, completion: (title: String) -> Void) {
        let profileUrl = NSURL(string:"http://www.facebook.com/" + identifier)!
        let task = NSURLSession.sharedSession().dataTaskWithURL(profileUrl) {
            (data, response, error) -> Void in
            if let urlContent = data {
                let webContent = NSString(data: urlContent, encoding: NSUTF8StringEncoding)
                let websiteArray = webContent!.componentsSeparatedByString("pageTitle\">")
                let secondArray = websiteArray[1].componentsSeparatedByString("</title>")
                let title = secondArray[0]
                completion(title: title)
                print(title)



                self.tableView.reloadData()
            }
        }
        task.resume()
    }



    //print(newArray)



    var titles = [String]()

    let queue = dispatch_queue_create("titles", DISPATCH_QUEUE_SERIAL)

    dispatch_apply(newArray.count, queue) { index in
        let identifier = newArray[index]
        fetchTitle(identifier) { title in
            dispatch_async(queue) {
                titles.append(title)
                array.append(title)


            }
        }
    }
func fetchTitle(identifier: String, completion: (title: String) -> Void) 
{
  let profileUrl = NSURL(string:"http://www.facebook.com/" + identifier)!
  let task = NSURLSession.sharedSession().dataTaskWithURL(profileUrl) {
    (data, response, error) -> Void in
    if let urlContent = data 
    {
      let webContent = NSString(data: urlContent, encoding: NSUTF8StringEncoding)
      let websiteArray = webContent!.componentsSeparatedByString("pageTitle\">")
      let secondArray = websiteArray[1].componentsSeparatedByString("</title>")
      let title = secondArray[0]
      //------------------------------------------
      //invoke the completion closure 
      //and the call to reloadData on the main thread.
      dispatch_async(dispatch_get_main_queue())
      {
        completion(title: title)
        print(title)
        self.tableView.reloadData()
      }
      //------------------------------------------
    }
  }
  task.resume()
}