Skip to content

Commit

Permalink
Sync up code
Browse files Browse the repository at this point in the history
  • Loading branch information
subdigital committed Jun 7, 2017
1 parent 034f509 commit e3c134b
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation
import CloudKit

protocol CKRecordWrapper : VendsCoding {
protocol CKRecordWrapper {
static var RecordType: String { get }

var record: CKRecord { get }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,3 @@ class CloudKitFolder : Folder, CKRecordWrapper {
self.record = record
}
}

extension CloudKitFolder {
static func defaultFolder(inZone zoneID: CKRecordZoneID) -> CloudKitFolder {
let recordID = CKRecordID(recordName: "DEFAULT_FOLDER", zoneID: zoneID)
let record = CKRecord(recordType: CloudKitFolder.RecordType, recordID: recordID)
let folder = CloudKitFolder(record: record)
folder.name = "My Notes"
return folder
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@

import Foundation

protocol VendsCoding {
func codable() -> NSCoding
static func fromCoding(decoder: NSCoder) -> Folder?
}

protocol Folder : VendsCoding {
protocol Folder {
var identifier: String? { get }
var name: String { get set }
var createdAt: Date? { get }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,16 @@
import Foundation

class FoldersDatasource {
let cache = DiskCache(name: "folders")
let noteManager: NotesManager

init(noteManager: NotesManager) {
self.noteManager = noteManager
}

func fetchFolders(completion: @escaping (Result<[Folder]>) -> Void) {
let cachedFolders: [Folder]? = cache.fetch()
if let folders = cachedFolders {
DispatchQueue.main.async {
print("Returning cached folders...")
completion(.success(folders))
}
}

noteManager.fetchFolders { result in
switch result {
case .success(let folders):
let codableFolders = folders.map { $0.codable() }
print("Caching updated results...")
self.cache.save(object: codableFolders)
DispatchQueue.main.async {
completion(.success(folders))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Foundation

class InMemoryFolder : Folder, NSCoding, VendsCoding {
class InMemoryFolder : Folder, NSCoding {
var identifier: String?
var name: String
var createdAt: Date?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Foundation

class InMemoryNote : Note, NSCoding, VendsCoding {
class InMemoryNote : Note, NSCoding {
var identifier: String?
var content: String = ""
var createdAt: Date?
Expand Down

0 comments on commit e3c134b

Please sign in to comment.