0

Everything was going great until yesterday. This morning I opened up Xcode and was told updates had occurred and it was converting the Swift code to the new version. NSData is now returning nil. It had a value yesterday. Some of the code below that was modified too automatically during the update, however for now until NSData is fixed that part doesn't matter.

    var data : NSData?
    let endpoint = NSURL(string: ProductListQuery.toString())
    let QOS = Int(QOS_CLASS_USER_INITIATED.rawValue)

    dispatch_async(dispatch_get_global_queue(QOS,0))
    {
        data = NSData(contentsOfURL: endpoint!)
        dispatch_async(dispatch_get_main_queue())
        {
            if (data != nil)
            {
                if let json: NSDictionary = (try? NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.MutableContainers)) as? NSDictionary
                {
                    if let items = json["result"] as? NSArray
                    {
                        for item in items
                        {
                            if let p = item as? NSDictionary
                            {
                                let lp = LcboProduct(lproduct:p)
                                self.ProductList.updateValue(lp, forKey:lp.Product_Id())
                            }
                        }
                    }
                    if let pageinfo = json["pager"] as? NSDictionary
                    {

                        self.ProductListQuery.Pager.set_Data(pageinfo)

                    }
                }

            }
        }
    }
    return ( ProductList.count > 0)
rmaddy
  • 298,130
  • 40
  • 468
  • 517
bhardy
  • 83
  • 9
  • Is endpoint an `https:` URL? Are there any messages in the console? – rmaddy Sep 22 '15 at 21:04
  • BTW - use the `contentsOfURL:options:` initializer which throws an exception instead of simply returning `nil`. Then you can see what the issue is. – rmaddy Sep 22 '15 at 21:06
  • Yes, it is. In fact, its demanded by the lcbo api. https://lcboapi.com/docs/v1#https No, there are no messages. – bhardy Sep 22 '15 at 21:08
  • Try my 2nd comment and see what you get. – rmaddy Sep 22 '15 at 21:10
  • Ok, thanks. I'm working at it. Very new to swift. – bhardy Sep 22 '15 at 21:12
  • Actually, I'm wrong. There is a message in the console: NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802) Exception catches error code value = 0. – bhardy Sep 22 '15 at 21:27
  • Do a search on the error. It's been discussed many times already. – rmaddy Sep 22 '15 at 21:28
  • Don't know why I missed the console error, but searching for it has given me a working fix. Thanks. https://forums.developer.apple.com/message/5857#5857 – bhardy Sep 22 '15 at 21:50

0 Answers0