Created
June 3, 2017 03:17
-
-
Save imothee/04318d8e7c92bccadcc68a4e75dd9fae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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