Messages allow you to display notifications (like errors or warnings) on specific lines. Messages are reported by adding them to a Set<TextLocated<Message>> binding. The editor automatically removes messages from lines that are edited.
Creating a Message
Use the following initializer:
init(category: Message.Category, length: Int, summary: String, description: NSAttributedString?)
- summary: A short string displayed inline on the right side of the code view.
- description: An optional detailed version shown in a popup when the user taps the summary.
- length: The number of characters to mark (implementation pending).
Locating Messages
Messages must be wrapped in a TextLocated<Entity> struct to specify where they appear:
struct TextLocated<Entity> {
let location: TextLocation
let entity: Entity
}
struct TextLocation {
let zeroBasedLine: Int // starts from line 0
let zeroBasedColumn: Int // starts from column 0
}
During editing, messages stick to their reported line number even if text is added above them.
// Example of creating a message
let errorMsg = Message(
category: .error,
length: 0,
summary: "Type Error",
description: NSAttributedString(string: "Expected String, found Int")
)
let locatedMsg = TextLocated(location: TextLocation(zeroBasedLine: 5, zeroBasedColumn: 0), entity: errorMsg)
// Add to your messages set to display
messages.insert(locatedMsg)