Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/marcoeidinger/xcsnippets
Swift package to interact with Xcode Code Snippets in a type-safe manner
https://github.com/marcoeidinger/xcsnippets
codesnippets swiftpackage xcode
Last synced: about 1 month ago
JSON representation
Swift package to interact with Xcode Code Snippets in a type-safe manner
- Host: GitHub
- URL: https://github.com/marcoeidinger/xcsnippets
- Owner: MarcoEidinger
- License: mit
- Created: 2022-06-11T16:41:16.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-06-16T12:45:20.000Z (over 2 years ago)
- Last Synced: 2024-10-13T21:32:39.074Z (2 months ago)
- Topics: codesnippets, swiftpackage, xcode
- Language: Swift
- Homepage:
- Size: 30.3 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# XCSnippets
[![Build](https://github.com/MarcoEidinger/XCSnippets/actions/workflows/swift.yml/badge.svg)](https://github.com/MarcoEidinger/XCSnippets/actions/workflows/swift.yml)
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FMarcoEidinger%2FXCSnippets%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/MarcoEidinger/XCSnippets)
[![](https://img.shields.io/badge/Documentation-DocC-blue)](https://swiftpackageindex.com/MarcoEidinger/XCSnippets/main/documentation/xcsnippets)Swift package to provide type-safe interaction with (user-defined) Xcode Code Snippets
## Overview
```swift
import XCSnippetslet 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
```swift
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.