The sketch on the phone
On this page
A sketch written for the Mac runs on an iPhone or an iPad without changes. It uses the same Metal renderer, the same draw() at the display's refresh rate, and the same shaders compiled from source at launch. A finger is the pointer, so mouseX, mouseY, and mouseIsPressed read the touch with no change, and a stylus fills pressure.
You work on it with one command:
ollin phone Sketch.swiftThe sketch appears on the phone, and every save on the Mac installs the new version there. The phone's parameters open in a browser on the Mac, and changes travel in both directions. Stop the command when you are done, and the app stays on the phone.
Contents
- What a save does
- The parameters on the Mac
- What comes along
- The canvas on the screen
- The options
- In the simulator
- In an app of your own
- Without installing it
- What it needs
What a save does
A phone runs only code that is signed inside its app bundle. Nothing can be pushed into a running app the way the live window swaps a sketch on the Mac. So a save is a small build and a reinstall, and the times are short enough for that to work:
| Step | Time |
|---|---|
| The framework, built for the phone | about 80 s, once |
| A save: the sketch recompiled, the app relinked and signed | 5 to 7 s |
| The app installed again, over Wi-Fi | about 2.5 s |
A save reaches the screen in under ten seconds. The app writes its state down every second and reads it back when it launches. That state is the clock, the seed, every @Param value, and every @Saved property. So a reinstall carries on mid-motion. An animation keeps its phase, and a value you tuned stays tuned. The phone keeps the same behavior as --keep-clock on the Mac.
The phone has to meet two conditions. It must be unlocked for the Mac to open the app. If it is locked, the new version is installed and waits for a tap. It must also be reachable, either on the cable or awake on the same network as the Mac.
The command prints a compile error with your own file and line, and the phone keeps running the last version until the next save.
The parameters on the Mac
The app serves its @Param parameters through the remote surface, which is the same touch surface you tune an installation from. The command prints the address and opens it:
parameters http://localhost:9330 or http://Edgardos-iPhone.local:9330Over the cable the surface is forwarded to localhost, so no network is needed between the two. Over Wi-Fi the address is the phone's own name. Drag a slider on the Mac and the phone follows between frames. Tune something on the phone and the Mac shows it. A value you settle on is carried across every later save, because it is part of the state the app writes down. To put it into the file, type it in.
Shaders in a .metal file beside the sketch come along as resources, so a shader edit is one more save.
What comes along
The sketch file is referenced where it is. The one exception is a sketch marked @main, as every sketch written for the Mac is. The command's own host owns the entry point, so it compiles a copy of the file with that attribute blanked to spaces. The copy is written again on every save. Every line and column stays where it was, and a build error names your file. Files beside it with a resource extension are copied into the app. That covers images, sounds, video, fonts, data, meshes, and .metal shaders. Bundle.module is the app, so loadImage( finds on the phone what it found on the Mac. Drop a new file beside the sketch and the next save takes it along. A recording of the phone's stream beside the sketch is a folder ending in .ollinrecording. It goes in as that folder, so the sketch opens it by name there too.
Every import Ollin… line links that satellite into the app. Ten have been built and run on a phone: OllinRemote, OllinPhysics, OllinOSC, OllinMIDI, OllinController, OllinVideo, OllinBluetooth, OllinAudio, OllinVision, and OllinHaptics. A satellite outside that list is linked too, and the command names it, so you know what to check first if the build fails. Four satellites work only on the Mac, so the command refuses them and gives the reason. They are the virtual camera, Syphon, screen capture, and the reader of another app's depth stream over the cable.
OllinPhone is not among them. In a sketch on a phone, its PhoneDevice() reads that phone's own sensors. So a sketch that draws in the room the phone sees runs there with no Mac. It builds for a phone and has not yet run on one.
A sketch that opens a sensor has the system's question written into its app. That is the camera for OllinPhone and OllinVision, the microphone for OllinAudio, and Bluetooth for OllinBluetooth. An app that opens a sensor without that line is closed by the system, not asked, so the line follows the import.
The Mac features stay on the Mac. They are the export flags, the screen saver, the wallpaper, the menu-bar strip, the display wall, the detached inspector panel, and the source-editing drag. A sketch that uses none of them is portable as written.
The canvas on the screen
A canvas of a set size keeps its shape on a phone. It is fitted whole inside the screen and centered, with black around it, and a touch lands on the canvas point under the finger. A canvas three across and four down on a tall phone has a black band above it and one below.
A sketch that wants the whole screen sets windowMode to .resizable. Its canvas then has no set size: it is the size of the screen, in points.
A small control at the foot of the screen keeps what the sketch shows in Photos: the camera button saves a picture, and the red one records a video with the sketch's sound. saveFrame() and startRecording() do the same from the sketch's code. Recording has the rest, including what happens when Photos is not allowed.
The options
ollin phone Sketch.swift the loop: build, install, launch, watch
ollin phone Sketch.swift --once build, install, launch, and stop
ollin phone Sketch.swift --fresh start the sketch over, state forgotten
ollin phone Sketch.swift --device iPad which paired device, by part of its name
ollin phone Sketch.swift --simulator the iOS simulator in place of a device
ollin phone Sketch.swift --no-open print where the parameters are, open nothing
ollin phone Sketch.swift --team ABCDE12345
ollin phone --devices the paired devicesThe signing team comes from the --team flag first, then from OLLIN_TEAM in the environment. If neither is set, the team is the one the reference phone app in the checkout is signed with. The project the command writes lives under ~/, with one folder per sketch. The sketches share one build folder, so the framework compiles for the phone only once.
In the simulator
ollin phone Sketch runs the sketch in the iOS simulator in place of a phone. It takes the simulator that is already booted, or starts the first iPhone this Mac has one of. --device picks one by part of its name. No phone is needed and nothing is signed for one.
It is for a first look, and it shows part of the picture:
- What draws. 2D drawing, text, images, and the picture of a recording of the phone's stream. A canvas sits on the simulated screen as it will on a phone.
- What does not. A 3D mesh is left out. The simulated GPU gives a shader fewer texture slots than the lit mesh shader names, so that pipeline cannot be built there. The app says so once in its console, and the command says so before it builds. No other kind of 3D drawing has been tried there.
- No camera. A sketch that reads the phone's sensors is told that the mode cannot run. It plays its recording, if it keeps one.
Judge a sketch with 3D in it on a phone.
In an app of your own
The command writes a throwaway app around the sketch, under the caches folder. For an app you keep and hand out, the project generator writes the same shape as a project of its own:
ollin new Rings --kind ios-app --team ABCDE12345
cd Rings && xcodegen generate && open Rings.xcodeprojThe folder holds the sketch, marked @main as on the Mac, and a one-line Bundle+Module.swift that points Bundle.module at the app. Beside them are the property list and the project.yml the Xcode project is written from. The .xcodeproj is never edited by hand and is not kept in git. Leave the team off and Xcode asks for it the first time you press Run, but what Xcode writes is lost when the project is generated again, so the README says to put it into project.yml. Every template fits, and so does any example that stays off the Mac-only libraries: a capability that lives on the Mac (Syphon, screen capture, the virtual camera, the phone link) is refused with its reason. A .metal file beside the sketch is copied by a copy-files phase, because the resources phase would compile it into a library the framework never reads. The generator window offers the same kind from its menu, with a field for the team.
Apps/OllinSketchApp in the checkout is the same shape, written by hand, with the framework as a local package.
@main on the sketch does on a phone what it does on the Mac. There Sketch.main() opens a window. Here it starts an app the framework carries, with the canvas on the whole screen and the status bar and the home indicator hidden. A checkpoint the sketch declares in its installation is kept. A piece that declares an installation keeps the screen awake, unless it sets keepsDisplayAwake to false.
The sketch's @Params open from the app itself: a panel beside the canvas on an iPad or a Mac, a sheet on an iPhone. A build you run from Xcode shows a small button in the top corner for them. It shows whatever the sketch declares, a checkpoint included, since a phone has no keyboard. An archive for TestFlight or the App Store never shows it, so what you hand to somebody else carries no tuning control over the art. Command-/ on a keyboard opens them in any build. A value turned there lasts for the run: the app cannot write it back into the sketch file, which lives on the Mac. A checkpoint carries it across a relaunch, and the final numbers go into the sketch by hand.
To set the sketch up before it runs, write the entry point yourself and hand the sketch to OllinApp.run:
import Ollin
import OllinRemote
@main
enum Launch {
@MainActor static func main() {
let sketch = Waves()
sketch.extend(RemoteInspector(port: 9330)) // the parameters in a browser, too
OllinApp.run(sketch)
}
}An app with a launch of its own (more than one window, chrome of its own) writes its own App and puts the sketch in a SketchView:
import SwiftUI
import Ollin
@main
struct MyApp: App {
// `Scene` is spelled out: the framework has a 3D `Scene` of its own.
var body: some SwiftUI.Scene {
WindowGroup {
SketchView(Waves(), onRunner: { runner in
// Optional: the state written down and read back at launch.
runner.beginInstallation(Installation(checkpoint: .every(seconds: 30)))
})
.ignoresSafeArea()
.statusBarHidden()
}
}
}That app owns the entry point, so @main goes on the App rather than on the sketch. A SketchView alone reads nothing from the sketch's installation, so a host of its own begins the checkpoint itself. The command's own host calls beginInstallation with a checkpoint every second. But a sketch that runs on a tablet in a room can use a checkpoint every minute instead.
Without installing it
There is a second way to put a sketch in your hand, and it installs nothing. The sketch keeps running on the Mac, and the phone shows its frames:
import Ollin
import OllinPhone
final class Held: Sketch {
let device = PhoneDevice()
override func setup() {
device.show(self)
}
}The Mac compresses each frame as video and sends it down the cable to Ollin Capture, which shows it full screen. The first finger on the picture is the sketch's pointer, just as it is on this page. So mouseX, mouseY, mouseIsPressed, and pressure read the same either way. Two fingers on the shown picture also pinch and turn the sketch through pinchScale and turnAngle, as they do on the Mac's trackpad. A sketch installed on the phone reads one finger only.
The two answer different questions. Showing the picture tells you how the sketch looks and plays in the hand. An edit appears as soon as the Mac has compiled it, through the live window's own reload. Installing tells you whether the phone's own GPU keeps up, and that the sketch runs with no Mac at all. Both suit a sketch in progress: showing it while you shape it, installing it when you want to know it holds.
What it needs
- iOS 26 on the phone or tablet. The device is paired with the Mac and trusted, with Developer Mode on.
- Xcode 26, and
xcodegen(brew install xcodegen), which writes the project. - A signing team the device is registered with. The first build asks Xcode to update the profile.
- A device for anything with 3D in it. The simulator runs a 2D sketch and draws no 3D mesh.