Swiftpack.co - MarcoEidinger/XCSnippets as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by MarcoEidinger.
MarcoEidinger/XCSnippets 1.1.0
Swift package to interact with Xcode Code Snippets in a type-safe manner
⭐️ 4
🕓 1 year ago
.package(url: "https://github.com/MarcoEidinger/XCSnippets.git", from: "1.1.0")

XCSnippets

Build

Swift package to provide type-safe interaction with (user-defined) Xcode Code Snippets

Overview

import XCSnippets

let directory = PersistentCodeSnippetDirectory() // points to ~/Library/Developer/Xcode/UserData/CodeSnippets

// CREATE (or override)
let newSnippet = XCSnippet(title: "MyFirstCodeSnippet", content: "print(\"Hello World\")")
try directory.write(contents: [newSnippet]) // alternative: try newSnippet.write(to: URL.codeSnippetsUserDirectoryURL)

// READ
let existingSnippets: [XCSnippet] = try dir.readContents()

// DELETE
try dir.delete(contents: existingSnippets) // alternative:try dir.delete(contentWithId: newSnippet.id)

Example how to copy a remote .codesnippet file to your local machine

try await URLSession.shared.data(from: URL(string: "https://raw.githubusercontent.com/burczyk/XcodeSwiftSnippets/master/swift-forin.codesnippet")!)
    .0
    .toXCSnippet()
    .write(to: .codeSnippetsUserDirectoryURL)

Note: programmatic changes in file directory ~/Library/Developer/Xcode/UserData/CodeSnippets will be ignored by a running Xcode application. You need to restart Xcode to see changes in the Snippets library.

GitHub

link
Stars: 4
Last commit: 1 year ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Related Packages

Release Notes

1 year ago

⚠ BREAKING CHANGES

✏️ Renamed package and its product from XCodeSnippets to XCSnippets ✏️ Renamed structs XCodeSnippets / XCodeSnippet accordingly to XCSnippets / XCSnippet

Features

🎸 XCSnippet conforms to Identifiable and Hashable

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