Skip to content

Instantly share code, notes, and snippets.

@jhoughjr
Last active July 23, 2018 03:05
Show Gist options
  • Save jhoughjr/b75d50da0d9a82ca1991f4766216a2e9 to your computer and use it in GitHub Desktop.
Save jhoughjr/b75d50da0d9a82ca1991f4766216a2e9 to your computer and use it in GitHub Desktop.
#import FileKit
/*
...
*/
func docNoteRTFData(for docID:String,
inApp bundleID:String) -> String {
SwiftyBeaver.debug("docID is \(docID)")
if bundleID != "com.apple.finder" {
// do {
// let a = ghostnotesPath()
// SwiftyBeaver.debug("Trying \(a)")
// return try TextFile(path: a ).read()
// }
// catch {
// SwiftyBeaver.error(error)
// }
}else {
do {
let i = docID.index(of: ":")!
let newDocID = String(docID.suffix(from: i).replacingOccurrences(of: ":",
with: "/"))
let b = (ghostnotesPath() + String(newDocID) + " Note.rtfd/TXT.rtf")
/* breakpoint */ SwiftyBeaver.debug("Trying \(b)")
return try TextFile(path: b ).read()
}
catch {
SwiftyBeaver.error(error)
}
}
return "burrrrp"
}
(lldb) po b is String
false
(lldb) po b is Path
true
(lldb) po newDocID is String
true
(lldb) po docID is String
true
(lldb) po ghostnotesPath() is Path
true
(lldb) po TextFile(path: b).read()
▿ FileKitError(Could not read from file at "/Users/jimmyhoughjr/Library/Application Support/com.ghostnoteapp.Ghostnote/GhostNotes/AnySequence<Path>(_box: Swift._SequenceBox<Swift._DropFirstSequence<FileKit.DirectoryEnumerator>>)/ Note.rtfd/TXT.rtf") Error Domain=NSCocoaErrorDomain Code=260 "The file “TXT.rtf” couldn’t be opened because there is no such file." UserInfo={NSFilePath=/Users/jimmyhoughjr/Library/Application Support/com.ghostnoteapp.Ghostnote/GhostNotes/AnySequence<Path>(_box: Swift._SequenceBox<Swift._DropFirstSequence<FileKit.DirectoryEnumerator>>)/ Note.rtfd/TXT.rtf, NSUnderlyingError=0x608000242820 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}
▿ readFromFileFail : 2 elements
▿ path : Path("/Users/jimmyhoughjr/Library/Application Support/com.ghostnoteapp.Ghostnote/GhostNotes/AnySequence<Path>(_box: Swift._SequenceBox<Swift._DropFirstSequence<FileKit.DirectoryEnumerator>>)/ Note.rtfd/TXT.rtf")
▿ _fmWraper : <_FMWrapper: 0x60000022dd80>
- rawValue : "/Users/jimmyhoughjr/Library/Application Support/com.ghostnoteapp.Ghostnote/GhostNotes/AnySequence<Path>(_box: Swift._SequenceBox<Swift._DropFirstSequence<FileKit.DirectoryEnumerator>>)/ Note.rtfd/TXT.rtf"
(lldb) po ghostnotesPath()
▿ Path("/Users/jimmyhoughjr/Library/Application Support/com.ghostnoteapp.Ghostnote/GhostNotes/")
▿ _fmWraper : <_FMWrapper: 0x608000037e40>
- rawValue : "/Users/jimmyhoughjr/Library/Application Support/com.ghostnoteapp.Ghostnote/GhostNotes/"
(lldb) po newDocID
"/Users/jimmyhoughjr/workspace/application/Ghostnote 2.xcodeproj/"
(lldb) po String(newDocID)
"/Users/jimmyhoughjr/workspace/application/Ghostnote 2.xcodeproj/"
(lldb)
func appNoteRTFData(for bundleID:String) -> String {
let paths = ghostnotesPath().find { (p) -> Bool in
let a = p.standardRawValue.components(separatedBy: "/").contains(bundleID)
return a
}
guard let path = paths.first else {return "???"}
do {
let file = try TextFile(path: path + " Note.rtfd/TXT.rtf").read()
return file
}
catch {
SwiftyBeaver.error(error)
return "???"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment