0

so i started using swift for the first time about 22 hrs ago. and so far so good, I have an app that lists dogs when you add them to the list.

Now I'm trying to link this up with a PHP server and a database. so when the app runs, it should get a list of dogs from the server (a working example is shown in this picture:

enter image description here

this is run on the same mac as the IOS simulator which throws this error when I run the app:

enter image description here

I've worked out that data is nill when it reaches the print statement. I can't work out why it's nil though.. Have i missed something? Can anyone see what the problem is here?

anything else you want to see, leave a comment and i'll be happy to provide.

thanks

Extra Information

At dan's suggestion i typed in po error and got the following returned:

 Optional<NSError>
  - Some : Error Domain=NSURLErrorDomain Code=-1002 "unsupported URL"
 UserInfo={NSErrorFailingURLStringKey=192.168.0.8/classes/main.php?
 fn=dogBoardingGet, NSErrorFailingURLKey=192.168.0.8/classes/main.php?
 fn=dogBoardingGet, NSLocalizedDescription=unsupported URL, 
 NSUnderlyingError=0x7c434860 {Error Domain=kCFErrorDomainCFNetwork 
 Code=-1002 "(null)"}}
Jamie McAllister
  • 729
  • 2
  • 11
  • 33
  • From what I can see, you have a number that's not part of the json response right at the start – webjunkie Sep 07 '16 at 20:59
  • I removed that and tried again, same error. From what i can tell, data is nil... But i don't understand why 0.o... have i missed something important? – Jamie McAllister Sep 07 '16 at 21:06
  • Look at the error passed into the completion handler to see why it failed. – dan Sep 07 '16 at 21:26
  • @dan what's the completion handler? (big downside to learning new technologies?... you sound like a complete noob! lol) – Jamie McAllister Sep 07 '16 at 21:31
  • 1
    The block that your print statement is in is called a completion handler, it runs when your network call is finished. Along with the data parameter that is passed into it which you are accessing there is also a response parameter and an error parameter. The error parameter will have more information about why your call is failing. – dan Sep 07 '16 at 21:46
  • @dan thanks, so on a related note, when i get this working, I handle the response in the block where the print statement is? (in this case, I'll be making classes for each dog) ---------- The error passed into the handler is shown bottom Left of the 2nd screenshot, if i expand `ObjectiveC.NSObject`there's nothing to see. I'm not really sure what to make of that, or how it helps .... If i change the print line to say `data: error` the build fails with no errors anywhere that i can see – Jamie McAllister Sep 07 '16 at 21:56
  • 1
    You can type `po error` next to where it says `(lldb)` on the right and it should print out a better description of the error. – dan Sep 07 '16 at 21:58
  • @dan I got added the error to the bottom of the question. thanks, `unsupported URL`?.... do i need the "HTTP://"? – Jamie McAllister Sep 07 '16 at 22:04
  • HTTP changed the error!... ` App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure.` – Jamie McAllister Sep 07 '16 at 22:07
  • for anyone who followed this and arrived at the same problem as my last comment: the solution is this image: http://i.stack.imgur.com/LqXFE.png – Jamie McAllister Sep 07 '16 at 22:13

0 Answers0