1

I'm trying to make an async request inside XCode 7.3 playground, using Alamofire. I've included two additional statements - needsIndefiniteExecution = true and finishExecution() as described in this answer: https://stackoverflow.com/a/33536290/603268.

import Foundation
import Alamofire
import XCPlayground

XCPlaygroundPage.currentPage.needsIndefiniteExecution = true

print("Before request")

Alamofire
    .request(.GET, "http://jsonplaceholder.typicode.com/users")
    .responseString { res in
        print(res)
        XCPlaygroundPage.currentPage.finishExecution()
    }
    //.resume() - adding this did not help

I've also set the playground execution mode to manual.

The first time, everything works fine, the response is printed and the playground finishes execution.

However, if I run it second time, it hangs and does not print any output (even no "Begin request"). I have to restart XCode to make it work again.

Community
  • 1
  • 1
Maciej Wozniak
  • 1,174
  • 15
  • 27

1 Answers1

0

You could try to remove:

XCPlaygroundPage.currentPage.finishExecution()
dasdom
  • 13,975
  • 2
  • 47
  • 58
  • Yeah, it solves the issue with consecutive runs, but it has its drawbacks too - it either keeps playground running for ~30 seconds or I have to manually stop it (as described here http://stackoverflow.com/a/24066317/603268). I was hoping for a cleaner solution – Maciej Wozniak Apr 09 '16 at 17:42