Last active
March 1, 2021 23:37
-
-
Save ryangittings/938496f9414c0b9e075775a863987b25 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
import CoreData | |
import SwiftUI | |
struct ContentView : View { | |
var request: FetchRequest<Task> | |
init(taskID: Int) { | |
self.request = FetchRequest<Task>(fetchRequest: ContentViewTest.taskRequest(taskID: taskID)) | |
} | |
var tasks: [Task] { | |
return request.wrappedValue.compactMap({ $0 }) | |
} | |
var body: some View { | |
List { | |
ForEach(self.tasks, id: \.self) { task in | |
Text(String(task.id)) | |
} | |
} | |
} | |
static func taskRequest(taskID: Int) -> NSFetchRequest<Task> { | |
let request: NSFetchRequest<Task> = Task.fetchRequest() | |
request.predicate = NSPredicate(format: "id == %d", taskID) | |
request.sortDescriptors = [NSSortDescriptor(key: "id", ascending: true)] | |
return request | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment