swiftuinsfetchrequest

How can I fetch value from CoreData to Variable?


CoreData:

Item

Fetch request

@FetchRequest(
        sortDescriptors: [NSSortDescriptor(keyPath: \Item.timestamp, ascending: true)],
        animation: .default)
    private var items: FetchedResults<Item>

How can I apply last added userName in Items value to var X ?


Solution

  • Thanks to @vadian

    var x = items.last?.userName ?? ""