Swiftpack.co - ICToolkit/SwiftyMonaco as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
ICToolkit/SwiftyMonaco
SwiftyMonaco is a wrapper for Monaco Editor from Microsoft
.package(url: "https://github.com/ICToolkit/SwiftyMonaco.git", from: "v0.1.1")

SwiftyMonaco

SwiftyMonaco is a wrapper for Monaco Editor from Microsoft.

image

How to use?

There is a simple example of how to use SwiftyMonaco

import SwiftUI

struct EditorView: View {
    @State var text: String
    
    var body: some View {
        SwiftyMonaco(text: $text)
    }
}

Remember! You should allow outgoing internet connections in your app before using this library, because Monaco Editor runs inside WKWebView and macOS considers it as an outgoing internet connection (Network -> Outgoing connections (Client)):

image

Syntax Highlighting

Also you can use SwiftyMonaco with syntax highlighting by passing SyntaxHighlight rule:

import SwiftUI

struct EditorView: View {
    @State var text: String
    
    var body: some View {
        SwiftyMonaco(text: $text)
            .syntaxHighlight(.systemVerilog)
    }
}

Default SyntaxHighlights

SyntaxHighlight Language
.swift Swift
.cpp C++
.systemVerilog Verilog/SystemVerilog

How to create your own SyntaxHighlight?

To create your own SyntaxHighlight you can use available initializers:

// With JS file containing syntax definition for Monarch
let syntax = SyntaxHighlight(title: "My custom language", fileURL: Bundle.module.url(forResource: "lang", withExtension: "js", subdirectory: "Languages")!)
// With a String containing syntax definition for Monarch
let syntax = SyntaxHighlight(title: "My custom language", configuration: "...")

You can create your own syntax at Monaco Editor Monarch website

Interface theme detection

SwiftyMonaco automatically detects interface theme changes and updates Monaco Editor theme according to it without dropping the current state of the editor. image image

GitHub

link
Stars: 6
Last commit: 3 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics