-
-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathmain.swift
More file actions
26 lines (19 loc) · 995 Bytes
/
main.swift
File metadata and controls
26 lines (19 loc) · 995 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import JavaScriptKit
// This function is automatically generated by the @JS plugin
// It demonstrates how to use TypeScript functions and types imported from bridge-js.d.ts
@JS public func run() throws(JSException) {
// Call the imported consoleLog function defined in bridge-js.d.ts
try consoleLog("Hello, World!")
// Get the document object - this comes from the imported getDocument() function
let document = try getDocument()
// Access and modify properties - the title property is read/write
try document.setTitle("Hello, World!")
// Access read-only properties - body is defined as readonly in TypeScript
let body = try document.body
// Create a new element using the document.createElement method
let h1 = try document.createElement("h1")
// Set properties on the created element
try h1.setInnerText("Hello, World!")
// Call methods on objects - appendChild is defined in the HTMLElement interface
try body.appendChild(h1)
}