Takes your lame string with code and returns a NSAttributtedString with proper syntax highlighting.
- iOS 8.0+
- macOS 10.10+
CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:
$ gem install cocoapods
To integrate Highlightr into your Xcode project using CocoaPods, specify it in your
source 'https://github.com/CocoaPods/Specs.git' use_frameworks! target '<Your Target Name>' do pod 'Highlightr' end
Then, run the following command:
$ pod install
Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.
You can install Carthage with Homebrew using the following command:
$ brew update $ brew install carthage
To integrate Highlightr into your Xcode project using Carthage, specify it in your
carthage update to build the framework and drag the built
Highlightr.framework into your Xcode project.Highlightr
Highlightr provides two main classes:
This is the main endpoint, you can use it to convert code strings into NSAttributed strings.
let highlightr = Highlightr() highlightr.setTheme(to: "paraiso-dark") let code = "let a = 1" // You can omit the second parameter to use automatic language detection. let highlightedCode = highlightr.highlight(code, as: "swift")
A subclass of NSTextStorage, you can use it to highlight text on real time.
let textStorage = CodeAttributedString() textStorage.language = "Swift" let layoutManager = NSLayoutManager() textStorage.addLayoutManager(layoutManager) let textContainer = NSTextContainer(size: view.bounds.size) layoutManager.addTextContainer(textContainer) let textView = UITextView(frame: yourFrame, textContainer: textContainer)
It will never be as fast as a native solution, but it’s fast enough to be used on a real time editor.
It comes with a custom made HTML parser for creating NSAttributtedStrings, is pre-processing the themes and is preloading the JS libraries. As result it’s taking around of 50 ms on my iPhone 6s for processing 500 lines of code.
You can find the documentation for the latest release on cocoadocs.
Mobile App Development Best Practices – 21.09
iOS Closures vs. Delegates in Swift iOS How to use the new inspector SwiftUI view modifier How to create an...
2023 App Threat Report
In 2022 alone, the number of mobile app downloads surpassed a staggering 200 billion, emphasizing the pervasive presence of these...
ElectricSQL – Local-first sync layer for web and mobile apps
Local-first sync layer for web and mobile apps. Build reactive, realtime, local-first apps directly on Postgres. What is ElectricSQL? ElectricSQL...
GitHub Copilot Chat opened to individual developers
Like similar chatbots, Copilot Chat sits in the sidebar of the IDE, and developers can use it to have lengthy...
ComposeCard – A beautifully designed payment view library
ComposeCards is a beautifully designed payment view library for Credit and Debit Cards. Made using Jetpack Compose 🎉. It allows...
Mobile App Development Best Practices – 20.09
Airship has released another study of mobile users aka shoppers. A lot of interesting things about habits and tasks in...