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
lazy var persistentContainer: NSPersistentContainer = { | |
let container = NSPersistentContainer(name: "DemoApp") | |
container.loadPersistentStores(completionHandler: { (storeDescription, error) in | |
if let error = error as NSError? { | |
fatalError("Unresolved error \(error), \(error.userInfo)") | |
} | |
}) | |
return container | |
}() |
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
lazy var persistentContainer: NSPersistentContainer = { | |
let modelName = "MyDataModel" | |
guard let modelDir = Bundle(for: type(of: self)).url(forResource: modelName, withExtension: "momd") else { fatalError() } | |
guard let mom = NSManagedObjectModel(contentsOf: modelDir) else { fatalError() } | |
let container = NSPersistentContainer(name: modelName, managedObjectModel: mom) | |
container.loadPersistentStores(completionHandler: { (storeDescription, error) in | |
if let error = error as NSError? { | |
fatalError("Unresolved error \(error), \(error.userInfo)") | |
} |
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
// | |
// CodableFileBuffer.swift | |
// | |
// Created by Oliver Epper on 26.12.19. | |
// Copyright © 2020 Oliver Epper. All rights reserved. | |
// | |
import Foundation | |
import os.log |
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 func append(_ codable: T) { | |
// encode codable | |
guard let data = try? encoder.encode(codable) else { | |
fatalError("Cannot encode \(codable)") | |
} | |
// write to FileHandle | |
fileHandle.write(data) | |
fileHandle.write(",".data(using: .utf8)!) |
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
// after initializing | |
[ | |
// after writing the first codable | |
[{"id":1, "key": "value_one"}, | |
// after writing the second codable | |
[{"id":1, "key": "value_one"},{"id":2, "key": "another_value"}, | |
// the data that gets passed to the JSONDecoder looks like this |
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
struct MyCodable: Codable { | |
var id: Int | |
var key: String | |
} | |
let buffer = CodableFileBuffer<MyCodable>() | |
buffer.append(MyCodable(id: 1, key: "value_one")) | |
buffer.append(MyCodable(id: 2, key: "another_value")) |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>FILEHEADER</key> | |
<string> | |
// Created by ___FULLUSERNAME___ on ___DATE___. | |
// ___COPYRIGHT___ | |
//</string> | |
</dict> |
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 struct LineReader { | |
enum Error: Swift.Error { | |
case cannotOpenFile(URL) | |
} | |
private let subject = PassthroughSubject<String, LineReader.Error>() | |
var linePublisher: AnyPublisher<String, LineReader.Error> { | |
subject.eraseToAnyPublisher() | |
} |
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
import Foundation | |
import Combine | |
class LinePublisherSubscription<S: Subscriber>: Subscription where S.Input == String, S.Failure == LinePublisher.Error { | |
let url: URL | |
let linesToRead: Int? | |
var subscriber: S? | |
var openDemand = Subscribers.Demand.none |
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
// | |
// Created by Oliver Epper on 16.02.21. | |
// | |
// | |
import Combine | |
import Foundation | |
final class ReadOperation: Operation { | |
enum ReadOperationError: Error { |
OlderNewer