Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

Multiplatform Xcode app

This example starts with Apple's standard SwiftUI app template and adds a CodeViewer backed by every grammar in CodeViewerKitStandardLanguages.

  1. In Xcode choose File > New > Project, then Multiplatform > App.

  2. Choose SwiftUI for Interface, Swift for Language, and None for Storage.

  3. Set the deployment targets to iOS/iPadOS 18 or newer and macOS 15 or newer.

  4. Choose File > Add Package Dependencies and enter:

    https://github.com/cavs1910/CodeViewerKitStandardLanguages.git
    
  5. Add the CodeViewerKitStandardLanguages product to the app target. It supplies CodeViewerKit and the language modules transitively.

  6. Drag lorem-ipsum-html.txt into the project, enable Copy items if needed, and include it in the app target.

  7. Replace the two files generated by Xcode with CodeViewerExampleApp.swift and ContentView.swift. Rename the app type if your project uses a different name.

The store is owned by ContentView so it survives SwiftUI body updates and reuses completed highlighting. A larger app can instead create one store at its root and pass it to each feature that displays code.

CodeViewerCommands adds Command-Plus and Command-Minus while a viewer is focused. The same source files compile for macOS, iPhone, and iPad.

ContentView selects ExampleDocument.bundledHTML by default. It reads the roughly 500-line HTML sample from the app bundle and explicitly highlights it as HTML even though the resource uses a .txt extension. Change that one assignment to ExampleDocument.inlineSwift to use the inline Swift string instead. This keeps file-backed and in-memory source loading visible in the same example.