I'm only using swift snippets and also wanted to remove all these c, c++ and objC snippets. A cleanup in the file "/Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/Current/Resources/SystemCodeSnippets.codesnippets" seemed to work: I had only three swift snippets left in the code snippet library panel. Filtering and selection of these snippets worked but Xcode crashed several times when hitting the enter key, while in the filter field of the snippets.
So I restored the old file and had the full list again.
Searching here in stackoverflow convinced me not to delete the default snippets but to store them with the same ID and a higher version number as a user snippet.
As a little programming task I created a OS X Projekt and with the following code right in the applicationDidFinishLaunching of the generated AppDelegate.swift:
func applicationDidFinishLaunching(aNotification: NSNotification) {
let filepathOfSystemSnippets = "/Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/Current/Resources/SystemCodeSnippets.codesnippets"
let folderForUserSnippets = "\(NSHomeDirectory())/Library/Developer/Xcode/UserData/CodeSnippets"
print("reading \(filepathOfSystemSnippets)")
let arrayOfDicts = NSMutableArray(contentsOfFile: filepathOfSystemSnippets)
// print("arry has \(arrayOfDicts?.count) entries")
for (ix, dict) in arrayOfDicts!.enumerate() {
let userDict = NSMutableDictionary(dictionary: dict as! [NSObject : AnyObject])
userDict["IDECodeSnippetVersion"] = 2
userDict["IDECodeSnippetTitle"] = "free user snippet \(ix) "
userDict["IDECodeSnippetSummary"] = ""
userDict["IDECodeSnippetContents"] = ""
userDict["IDECodeSnippetLanguage"] = "Xcode.SourceCodeLanguage.Swift"
userDict["IDECodeSnippetCompletionPrefix"] = ""
userDict["IDECodeSnippetUserSnippet"] = true
if let id = dict["IDECodeSnippetIdentifier"] as? String {
let pathOfUserSnippet = "\(folderForUserSnippets)/\(id).codesnippet"
if NSFileManager.defaultManager().fileExistsAtPath(pathOfUserSnippet){
print("snippet with id \(id) already exists in \(pathOfUserSnippet) -> don't write.")
} else {
userDict.writeToFile(pathOfUserSnippet, atomically: false)
// print("write snippet with id \(id) in \(pathOfUserSnippet)")
}
}
}
}
I use the hardcoded folder names I found in the answers. So if they change in future versions of Xcode the may be needed to change.
After a run of the application the users snippet folder is populated with about 60 cleaned snippets ready to be filled with own source code.