dalezak/turbo-ios-base

Settings not loading from turbo.json

Closed this issue · 6 comments

Hey thanks for the awesome starting point for us who know nothing about Swift!

I'm not sure if this issue is related to my rails setup. I created a new project and followed the instructions from the readme.

CleanShot 2021-06-25 at 18 10 01

CleanShot 2021-06-25 at 18 13 26

Hmm, your turbo.json looks fine, try changing your print lines to

print("path \(path)")
print("text \(text)")

And also add print("json \(json)") inside the if let json block, that should output the contents.

Weird, right?

CleanShot 2021-06-25 at 19 37 05

CleanShot 2021-06-25 at 20 41 51

This seems to be working. The request must be made from WK View for any reason?

    func loadSettings() -> Dictionary<String, AnyObject> {
        let path = turboPath("/turbo.json")
        let url = URL(string: path)
        let semaphore = DispatchSemaphore(value: 0)
        var text: String = ""
        
        let task = URLSession.shared.dataTask(with: url!) {(data, response, error) in
            text = String(data: data!, encoding: String.Encoding.utf8)!
            semaphore.signal()
        }
        task.resume()
        semaphore.wait()

        if let json = stringToDictionary(text: text) {
            return (json["settings"] as? Dictionary<String, AnyObject>)!
        }
        return [:]
    }

Do you have @hotwired/turbo-rails in your package.json?

I just realized I forgot this in the instructions.

If you are using Yarn, do yarn add @hotwired/turbo-rails.

If you are using NPM, do npm add @hotwired/turbo-rails.

https://www.npmjs.com/package/@hotwired/turbo-rails

Alright @codigodo, I tested out your changes and they seem to work well.

So I've updated loadSettings to use URLSession.shared.dataTask instead.

Can you pull the latest to verify the changes still work for you?

Works great!

Good news, closing issue.