Swift
Write app and game logic in Swift. It's translated to C and built with devkitPro.
How it works
The Wii's processor has no Swift compiler, so Revolution Editor translates a subset of Swift to C each time you build. You write normal Swift; mistakes show up in the Console like swift/main.swift:12:5: error: ….
Start
Choose Swift: UI app or Game: Swift when you create a project, then edit swift/main.swift. Every .swift file in the swift/ folder is used.
Example
var count = 0
func appOnButton(_ id: Int) {
if id == UI.go {
count += 1
setText(UI.status, "Pressed \(count)")
}
}
UI.go is the widget called go in your screen design.
Functions the app calls
appOnStart()once at launch,appOnFrame()andappOnDraw()every frame (see Make a game).appOnButton(_ id: Int)when a button is clicked.appOnWpad(_ pressed: UInt32)when Wii Remote buttons are pressed.
What works
- Types:
Int,Double,Bool,String,UInt32,UInt8,Float, optionals (Int?), arrays, dictionaries, tuples, structs, classes, enums (with raw values or payloads) and protocols. - Generics:
Stack<Int>andfunc pick<T>(...). - Closures and
map,filter,reduce,sorted,forEach,contains;guard,if let,if case,switchwith patterns,??,?.. - Extensions, static and computed properties,
inout, nested functions, default arguments, string interpolation and common string methods. - Numbers don't convert on their own: write
Double(n)orInt(x). - Built in:
setText,getText,setVisible,setColor,randomInt,exitApp,print(shows in an on-screen log),abs,min,max,sqrt,sin,cos,pow, and the drawing, input and sound functions in Make a game.
Want screens built from views instead? See SwiftUI.
What doesn't
Class inheritance, protocol extensions, try/throw, defer, async/await and Foundation. Strings are limited to 127 characters, and classes are never freed. Each gives a clear error. For anything else, add a C file to source/; it works alongside the Swift.