From b8e8a7e1ce54fd53076a734f0f60203b663272e3 Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Wed, 21 Oct 2020 10:54:45 +0100 Subject: [PATCH] Update example code in `README.md` It was my mistake to convert the example code to the new style without checking it in a real app, turns out there were a few errors in the converted version. Calling `alert` on `JSObject.global` still requires force unwrapping. Also, dynamic properties can't be updated on `JSValue` constants, so need to convert `divElement` to a `var` binding. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8119d8c41..ae8c0fbc4 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ import JavaScriptKit let document = JSObject.global.document -let divElement = document.createElement("div") +var divElement = document.createElement("div") divElement.innerText = "Hello, world" _ = document.body.appendChild(divElement) @@ -50,7 +50,7 @@ struct Pet: Codable { let jsPet = JSObject.global.pet let swiftPet: Pet = try JSValueDecoder().decode(from: jsPet) -JSObject.global.alert("Swift is running in the browser!") +JSObject.global.alert!("Swift is running in the browser!") ``` ### Usage in a browser application