Skip to content

Instantly share code, notes, and snippets.

@imothee
Created June 3, 2017 03:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imothee/04318d8e7c92bccadcc68a4e75dd9fae to your computer and use it in GitHub Desktop.
Save imothee/04318d8e7c92bccadcc68a4e75dd9fae to your computer and use it in GitHub Desktop.
public static func noteTitles(content: String) -> (String, String) {
let lines = content.trimmingCharacters(in: .whitespacesAndNewlines).components(separatedBy: "\n")
let title = lines[0].characters.count > 0 ? lines[0] : "New Note"
let sub = lines.count > 1 ? lines[1] : ""
return (title, sub)
}
public static func loadNoteContent(note: Note) -> String {
let contentString = NSMutableString(string: "")
for op in note.operations {
print("Applying operation \(op)")
switch op.operationType {
case OperationType.insert.rawValue:
contentString.insert(op.content, at: op.cursor)
break
case OperationType.replace.rawValue:
contentString.replaceCharacters(in: NSMakeRange(op.cursor, op.length), with: op.content)
break
default:
break
}
}
print("Got content \(contentString)")
return String(contentString)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment