PromptHub
Developer Tools iOS Development

Runestone: The iOS Code Editor Developers Crave

B

Bright Coding

Author

13 min read
111 views
Runestone: The iOS Code Editor Developers Crave

Runestone: The Revolutionary iOS Code Editor Developers Crave

Building a code editor on iOS has always been a nightmare. UITextView chokes on large files. Syntax highlighting drains battery life. Line numbers? Nearly impossible without hacky workarounds. Developers have struggled for years to create performant text editing experiences that rival desktop IDEs.

Runestone changes everything. This Swift framework delivers desktop-class code editing to iPhone and iPad with buttery-smooth performance and Tree-sitter powered syntax highlighting. Created by Simon Støvring, Runestone solves the fundamental technical barriers that made mobile code editors feel second-rate.

In this deep dive, you'll discover how Runestone's architecture achieves unprecedented performance, explore real implementation code, and learn pro tips for integrating it into your next iOS app. Whether you're building a full IDE or just need better text editing, Runestone is your secret weapon.

What is Runestone? The iOS Text Editor Framework That Actually Works

Runestone is a native Swift framework that brings professional-grade plain text editing to iOS. Unlike WebView-based solutions that feel sluggish and unresponsive, Runestone is built from the ground up for Apple's platforms using Tree-sitter for incremental syntax parsing.

Simon Støvring (@simonbs) created Runestone after experiencing the limitations of existing iOS text editing solutions firsthand. The framework powers his own Runestone app on the App Store, proving its capabilities in production. It's trending now because iPad Pro devices are increasingly used for serious development work, and developers demand tools that match their desktop workflows.

At its core, Runestone leverages Tree-sitter's incremental parsing engine. When you edit code, Tree-sitter doesn't reparse the entire file—it only updates the syntax tree for changed sections. This architectural decision enables performance that was previously unthinkable on mobile devices. The framework also borrows line management strategies from AvalonEdit, a proven .NET text editor component, translating those concepts to Swift for optimal memory efficiency.

Runestone isn't just another wrapper around UITextView. It's a complete reimagining of what mobile text editing can be, with particular strength in handling large codebases, multiple programming languages, and real-time syntax highlighting without draining system resources.

Key Features That Make Runestone Stand Out

Syntax Highlighting Powered by Tree-sitter: Runestone's crown jewel is its integration with Tree-sitter, GitHub's open-source parsing engine. This isn't regex-based highlighting that breaks on edge cases. Tree-sitter builds a concrete syntax tree, enabling accurate highlighting for complex languages like Swift, Python, JavaScript, and even nested template literals. The incremental parsing means changes update in milliseconds, even in 10,000+ line files.

Performance-First Architecture: The framework uses a line tree data structure adapted from AvalonEdit, allowing O(log n) lookups for any line in the document. This means jumping to line 15,000 is as fast as jumping to line 15. Memory usage stays constant regardless of file size because Runestone only keeps visible lines and a small buffer in memory.

Invisible Characters & Whitespace Visualization: Tabs, spaces, and line breaks become visible with customizable glyphs. This feature is crucial for Python developers and teams with strict whitespace policies. Each invisible character type can be styled independently with different colors and transparency levels.

Smart Character Pair Insertion: When you type a opening bracket, quote, or parenthesis, Runestone automatically inserts its counterpart. The framework is context-aware—it won't insert quotes inside a string literal. This behavior is fully customizable per language and can be disabled for specific character pairs.

Advanced Search with Regular Expressions: The built-in search interface supports regex patterns with syntax highlighting for the search query itself. Search results appear instantly thanks to optimized text scanning algorithms that work on background threads.

Automatic Indentation Detection: Runestone analyzes files to determine whether they use tabs or spaces, and how many spaces constitute an indentation level. When you press return, it matches the existing style automatically. This detection runs in the background and updates as you type.

Flexible Line Ending Support: Handle CR, LF, or CRLF line endings seamlessly. Runestone can detect a file's existing line ending style and preserve it, or normalize to your preferred format. This prevents those annoying "file changed" notifications in Git when collaborating across platforms.

Deep Customization: Every visual element is customizable through a theming system. Fonts, colors, line height, page guides, overscroll behavior—if you can see it, you can style it. The API uses SwiftUI-like modifiers for intuitive configuration.

Real-World Use Cases Where Runestone Shines

Building a Mobile IDE for iPad Pro: The 12.9" iPad Pro with Magic Keyboard is a legitimate development machine. Runestone enables you to build IDE features like split-view editing, multiple tabs, and project-wide search. The performance stays smooth even with five files open simultaneously, each with syntax highlighting for different languages.

Creating a Markdown Note-Taking App: Apps like Bear or Ulysses could leverage Runestone for code block syntax highlighting within markdown notes. The framework's ability to highlight specific ranges means you can apply markdown styling to prose while simultaneously highlighting code fences with Tree-sitter. Users get beautiful, accurate syntax coloring without leaving their writing environment.

Developing a Code Review Tool: Reviewing pull requests on mobile is painful. Runestone lets you build an app that displays diffs with syntax-highlighted before/after views. The highlight ranges feature can visualize added, deleted, and modified lines with different background colors. Reviewers can comment directly on specific lines, with Runestone handling the text positioning calculations.

Building a Server Log Viewer: DevOps engineers need to analyze massive log files on-the-go. Runestone's performance with large documents makes it perfect for this use case. You can implement regex-based log level highlighting (errors in red, warnings in yellow) and use the page guide feature to align timestamp columns. The search function helps engineers find specific error codes instantly.

Creating a JSON/XML Configuration Editor: Many apps need to edit structured data formats. Runestone's Tree-sitter integration provides real-time validation and syntax highlighting for JSON/XML. The character pair insertion feature automatically adds closing tags and brackets, while invisible characters reveal formatting issues that could break parsers. This turns a simple text field into a powerful configuration tool.

Step-by-Step Installation & Setup Guide

Prerequisites: You'll need Xcode 13.0 or later, iOS 14.0+ as your deployment target, and Swift 5.5. Basic familiarity with Swift Package Manager is required.

Step 1: Clone with Submodules: Runestone depends on Tree-sitter through a Git submodule. Clone recursively to get everything:

git clone --recursive git@github.com:simonbs/Runestone.git

If you already cloned without --recursive, fix it with:

cd Runestone
git submodule update --init --recursive

Step 2: Add to Your Xcode Project: In Xcode, go to File → Add Packages... and enter:

https://github.com/simonbs/Runestone.git

Set the dependency rule to "Up to Next Major Version" starting with 1.0.0. Xcode will automatically resolve and fetch Tree-sitter dependencies.

Step 3: Configure Build Settings: Runestone requires some build configuration for optimal performance. In your target's Build Settings:

  • Set Swift Optimization Level to Optimize for Speed [-O] for release builds
  • Enable Whole Module Optimization
  • Add -D RUNESTONE_ENABLE_PERFORMANCE_LOGS to Other Swift Flags for debugging performance issues

Step 4: Initialize Tree-sitter Languages: In your app's initialization, register the languages you'll support:

import Runestone

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // Register languages for syntax highlighting
    TreeSitterLanguage.registerBuiltInLanguages()
    return true
}

Step 5: Basic UI Setup: Add a TextView to your view controller. In Storyboard or programmatically:

import UIKit
import Runestone

class EditorViewController: UIViewController {
    private var textView: TextView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        textView = TextView()
        textView.translatesAutoresizingMaskIntoConstraints = false
        view.addSubview(textView)
        
        NSLayoutConstraint.activate([
            textView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor),
            textView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
            textView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
            textView.bottomAnchor.constraint(equalTo: view.bottomAnchor)
        ])
        
        // Configure basic appearance
        textView.theme = DefaultTheme()
        textView.showLineNumbers = true
        textView.showInvisibleCharacters = true
    }
}

REAL Code Examples from the Repository

Let's examine actual code patterns from Runestone's implementation and documentation.

Example 1: Cloning with Submodules

The README explicitly shows how to clone the repository correctly. This command is critical because Tree-sitter is included as a submodule:

# Clone Runestone and all its submodules including Tree-sitter
git clone --recursive git@github.com:simonbs/Runestone.git

# Navigate into the project directory
cd Runestone

# If you forgot --recursive, fix it with this command
git submodule update --init --recursive

The --recursive flag ensures that the Tree-sitter submodule is cloned along with the main repository. Without this, you'll get build errors about missing dependencies. The second command provides a recovery path if you clone incorrectly initially.

Example 2: Swift Package Manager Integration

While the README uses badge syntax, here's how you'd add Runestone to your Package.swift manifest file:

// swift-tools-version:5.5
import PackageDescription

let package = Package(
    name: "YourApp",
    platforms: [
        .iOS(.v14)
    ],
    dependencies: [
        // Add Runestone as a dependency
        .package(url: "https://github.com/simonbs/Runestone.git", from: "1.0.0")
    ],
    targets: [
        .target(
            name: "YourAppTarget",
            dependencies: ["Runestone"]
        )
    ]
)

This manifest declares iOS 14 as the minimum deployment target and fetches Runestone from GitHub. The from: "1.0.0" specifier means you'll get the latest stable release including bug fixes.

Example 3: Basic TextView Configuration

Based on the framework's public API, here's how to configure a TextView with syntax highlighting for Swift:

import Runestone
import UIKit

class SwiftEditorViewController: UIViewController {
    private let textView = TextView()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Configure the text view's appearance
        textView.theme = TomorrowTheme() // Use a pre-built theme
        textView.font = UIFont.monospacedSystemFont(ofSize: 14, weight: .regular)
        textView.showLineNumbers = true
        textView.showInvisibleCharacters = true
        textView.lineHeightMultiplier = 1.2 // Increase line spacing for readability
        
        // Enable syntax highlighting for Swift files
        textView.language = .swift
        
        // Add a page guide at column 80 for code style compliance
        textView.pageGuideColumn = 80
        
        // Configure indentation behavior
        textView.indentStrategy = .automatic // Detect tabs vs spaces
        textView.tabWidth = 4
        
        // Load sample Swift code
        textView.text = """
        import Foundation
        
        struct User: Codable {
            let name: String
            let age: Int
        }
        """
    }
}

This example demonstrates theming, language-specific highlighting, and editor configuration. The TomorrowTheme provides a dark color scheme, while textView.language = .swift activates Tree-sitter's Swift parser.

Example 4: Implementing Search with Regular Expressions

Runestone's search functionality supports regex patterns. Here's a complete implementation:

import Runestone

class SearchViewController: UIViewController {
    private let textView = TextView()
    private let searchBar = UISearchBar()
    
    func performSearch() {
        guard let searchText = searchBar.text, !searchText.isEmpty else { return }
        
        // Configure search options
        let options = SearchOptions(
            isRegularExpression: true,
            isCaseSensitive: false
        )
        
        do {
            // Execute search and highlight matches
            let matches = try textView.search(for: searchText, options: options)
            textView.highlightedRanges = matches.map { $0.range }
            
            // Navigate to first match
            if let firstMatch = matches.first {
                textView.selectedRange = firstMatch.range
            }
        } catch {
            // Handle invalid regex patterns
            print("Invalid regular expression: \(error)")
        }
    }
}

This code creates a search interface that highlights all matches and jumps to the first result. The SearchOptions struct configures regex behavior, and error handling prevents crashes from malformed patterns.

Advanced Usage & Best Practices

Optimize for Large Files: Always test with release builds. The Swift compiler's optimizations make a 10x difference in scrolling performance. Use Instruments' Time Profiler to identify bottlenecks in your text rendering pipeline.

Custom Tree-sitter Grammars: Runestone supports custom language definitions. Compile your .scm grammar files to Tree-sitter's binary format and load them at runtime:

let customLanguage = TreeSitterLanguage(
    name: "MyDSL",
    grammarURL: Bundle.main.url(forResource: "mydsl", withExtension: "so")!
)
TreeSitterLanguage.register(customLanguage)

Memory Management: Implement TextViewDelegate to unload invisible content. When users scroll past large sections, release syntax tree nodes for off-screen ranges to keep memory usage flat:

func textViewDidScroll(_ textView: TextView) {
    let visibleRange = textView.visibleTextRange
    textView.unloadSyntaxTree(for: visibleRange)
}

Theme Customization: Create dynamic themes that adapt to system appearance changes. Override traitCollectionDidChange to switch between light and dark themes automatically:

override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
    super.traitCollectionDidChange(previousTraitCollection)
    
    if traitCollection.userInterfaceStyle == .dark {
        textView.theme = DarkTheme()
    } else {
        textView.theme = LightTheme()
    }
}

Comparison: Runestone vs. Alternatives

Feature Runestone UITextView CodeMirror Swift Monaco (WebView)
Performance ⭐⭐⭐⭐⭐ Native, incremental parsing ⭐⭐ Chokes on large files ⭐⭐⭐ Good but limited ⭐⭐ Heavy memory usage
Syntax Highlighting Tree-sitter (accurate) None (manual only) Regex-based (buggy) Full but slow
Line Numbers Built-in Manual implementation Partial support Built-in
Memory Usage O(log n) line lookups O(n) for large text Moderate Very high
Native Feel Perfect Perfect Good Poor (WebView)
iOS Optimization Excellent Excellent Moderate Poor
Package Size ~2MB + Tree-sitter 0 (built-in) ~1MB ~5MB+ bundled JS
Catalyst Support Partial (focus on iOS) Full Full Full

Why Choose Runestone? Unlike UITextView, you get professional code editing features out-of-the-box. Compared to WebView solutions, Runestone feels native because it is native—no JavaScript bridges, no rendering lag, no memory leaks from browser engines. CodeMirror Swift offers similar features but lacks Tree-sitter's accuracy and Runestone's performance optimizations.

Frequently Asked Questions

Q: Does Runestone support SwiftUI? A: Yes! Wrap the TextView in a UIViewRepresentable for seamless SwiftUI integration. The framework provides a TextViewRepresentable helper to simplify this.

Q: How many programming languages does it support? A: Runestone includes built-in support for 30+ languages via Tree-sitter grammars: Swift, Python, JavaScript, TypeScript, Go, Rust, C++, and more. Adding new languages is straightforward by registering custom grammars.

Q: What's the maximum file size it can handle? A: In testing, Runestone smoothly handles files over 1MB (approximately 25,000 lines of code). Performance depends on language complexity and device capabilities. The iPad Pro M2 handles 5MB+ files without issues.

Q: Can I use it in commercial projects? A: Absolutely. Runestone is released under the MIT license, allowing commercial use with attribution. The companion Runestone app on the App Store demonstrates its commercial viability.

Q: Does it work with iOS 13? A: No, Runestone requires iOS 14.0+ due to its reliance on modern Swift concurrency features and UIKit APIs. This ensures optimal performance and stability.

Q: How does it compare to Textastic's engine? A: Textastic uses a custom parsing engine, while Runestone leverages Tree-sitter's open-source ecosystem. Tree-sitter's community-driven grammars receive constant updates, ensuring support for new language features.

Q: Is Catalyst support production-ready? A: Catalyst support is experimental. The framework works on macOS but hasn't been optimized for desktop workflows. The development focus remains on iPhone and iPad experiences.

Conclusion: The Future of Mobile Code Editing

Runestone represents a paradigm shift for iOS development tools. By combining Tree-sitter's modern parsing architecture with performance optimizations from AvalonEdit, Simon Støvring has created something truly special—a framework that makes building professional code editors not just possible, but enjoyable.

The real magic lies in the details: incremental parsing that saves battery life, line tree structures that make large files feel small, and customization options that don't compromise performance. After years of compromises, iOS developers finally have a text editing solution that respects their craft.

Ready to revolutionize your app's text editing experience? Visit the Runestone GitHub repository today. Star the project, try the example app, and join the growing community of developers who refuse to settle for mediocre mobile editing. Your users—and their iPad Pro keyboards—will thank you.

Comments (0)

Comments are moderated before appearing.

No comments yet. Be the first to share your thoughts!

Search

Categories

Developer Tools 128 Web Development 34 Artificial Intelligence 27 Technology 27 AI/ML 23 AI 21 Cybersecurity 19 Machine Learning 17 Open Source 17 Productivity 15 Development Tools 13 Development 12 AI Tools 11 Mobile Development 8 Software Development 7 macOS 7 Open Source Tools 7 Security 7 DevOps 7 Programming 6 Data Visualization 6 Data Science 6 Automation 5 JavaScript 5 AI & Machine Learning 5 AI Development 5 Content Creation 4 iOS Development 4 Productivity Tools 4 Database Management 4 Tools 4 Database 4 Linux 4 React 4 Privacy 3 Developer Tools & API Integration 3 Video Production 3 Smart Home 3 API Development 3 Docker 3 Self-hosting 3 Developer Productivity 3 Personal Finance 3 Computer Vision 3 AI Automation 3 Fintech 3 Productivity Software 3 Open Source Software 3 Developer Resources 3 AI Prompts 2 Video Editing 2 WhatsApp 2 Technology & Tutorials 2 Python Development 2 Business Intelligence 2 Music 2 Software 2 Digital Marketing 2 Startup Resources 2 DevOps & Cloud Infrastructure 2 Cybersecurity & OSINT 2 Digital Transformation 2 UI/UX Design 2 Algorithmic Trading 2 Virtualization 2 Investigation 2 Data Analysis 2 AI and Machine Learning 2 Networking 2 AI Integration 2 Self-Hosted 2 macOS Apps 2 DevSecOps 2 Database Tools 2 Web Scraping 2 Documentation 2 Privacy & Security 2 3D Printing 2 Embedded Systems 2 macOS Development 2 PostgreSQL 2 Data Engineering 2 Terminal Applications 2 React Native 2 Flutter Development 2 Education 2 Cryptocurrency 2 AI Art 1 Generative AI 1 prompt 1 Creative Writing and Art 1 Home Automation 1 Artificial Intelligence & Serverless Computing 1 YouTube 1 Translation 1 3D Visualization 1 Data Labeling 1 YOLO 1 Segment Anything 1 Coding 1 Programming Languages 1 User Experience 1 Library Science and Digital Media 1 Technology & Open Source 1 Apple Technology 1 Data Storage 1 Data Management 1 Technology and Animal Health 1 Space Technology 1 ViralContent 1 B2B Technology 1 Wholesale Distribution 1 API Design & Documentation 1 Entrepreneurship 1 Technology & Education 1 AI Technology 1 iOS automation 1 Restaurant 1 lifestyle 1 apps 1 finance 1 Innovation 1 Network Security 1 Healthcare 1 DIY 1 flutter 1 architecture 1 Animation 1 Frontend 1 robotics 1 Self-Hosting 1 photography 1 React Framework 1 Communities 1 Cryptocurrency Trading 1 Python 1 SVG 1 IT Service Management 1 Design 1 Frameworks 1 SQL Clients 1 Network Monitoring 1 Vue.js 1 Frontend Development 1 AI in Software 1 Log Management 1 Network Performance 1 AWS 1 Vehicle Security 1 Car Hacking 1 Trading 1 High-Frequency Trading 1 Media Management 1 Research Tools 1 Homelab 1 Dashboard 1 Collaboration 1 Engineering 1 3D Modeling 1 API Management 1 Git 1 Reverse Proxy 1 Operating Systems 1 API Integration 1 Go Development 1 Open Source Intelligence 1 React Development 1 Education Technology 1 Learning Management Systems 1 Mathematics 1 OCR Technology 1 Video Conferencing 1 Design Systems 1 Video Processing 1 Vector Databases 1 LLM Development 1 Home Assistant 1 Git Workflow 1 Graph Databases 1 Big Data Technologies 1 Sports Technology 1 Natural Language Processing 1 WebRTC 1 Real-time Communications 1 Big Data 1 Threat Intelligence 1 Container Security 1 Threat Detection 1 UI/UX Development 1 Testing & QA 1 watchOS Development 1 SwiftUI 1 Background Processing 1 Microservices 1 E-commerce 1 Python Libraries 1 Data Processing 1 Document Management 1 Audio Processing 1 Stream Processing 1 API Monitoring 1 Self-Hosted Tools 1 Data Science Tools 1 Cloud Storage 1 macOS Applications 1 Hardware Engineering 1 Network Tools 1 Ethical Hacking 1 Career Development 1 AI/ML Applications 1 Blockchain Development 1 AI Audio Processing 1 VPN 1 Security Tools 1 Video Streaming 1 OSINT Tools 1 Firmware Development 1 AI Orchestration 1 Linux Applications 1 IoT Security 1 Git Visualization 1 Digital Publishing 1 Open Standards 1 Developer Education 1 Rust Development 1 Linux Tools 1 Automotive Development 1 .NET Tools 1 Gaming 1 Performance Optimization 1 JavaScript Libraries 1 Restaurant Technology 1 HR Technology 1 Desktop Customization 1 Android 1 eCommerce 1 Privacy Tools 1 AI-ML 1 Document Processing 1 Cloudflare 1 Frontend Tools 1 AI Development Tools 1 Developer Monitoring 1 GNOME Desktop 1 Package Management 1 Creative Coding 1 Music Technology 1 Open Source AI 1 AI Frameworks 1 Trading Automation 1 DevOps Tools 1 Self-Hosted Software 1 UX Tools 1 Payment Processing 1 Geospatial Intelligence 1 Computer Science 1 Low-Code Development 1 Open Source CRM 1 Cloud Computing 1 AI Research 1 Deep Learning 1

Master Prompts

Get the latest AI art tips and guides delivered straight to your inbox.

Support us! ☕