SwiftUI Picker in a TextField with Core Data, error “Result of 'Picker <Label, SelectionValue, Content>' initializer is unused”

An app of filing that has a form with a Picker and two entities behind, one-many relationship. Want to save a Picker value picked from one entity and save into the other, specifically a value picked from cateName.CatesEnt saved into fileName.FilesEnt via a TextField. Tried with the code below but got a yellow stopper error.

struct FileAddEdit: View {

@ObservedObject var fileData : FileVM
@Environment(\.managedObjectContext) var context
@FetchRequest(sortDescriptors: [NSSortDescriptor(keyPath: \CatesEnt.cateOrder, ascending: true)], animation: .default)
private var cates: FetchedResults<CatesEnt>
@State var selectedCate: CatesEnt? = nil
@State var cateName: [CatesEnt] 

...
HStack {
  Text("File Name:")
  TextField("required", text: $fileData.fileName)
}
HStack {
    Text("Folder:")
    TextField("select a folder", text: $fileData.fileCate)
    .onTapGesture {
        Picker(selection: $selectedCate, label: Text("folder: ")) {
        // yellow stopper waning: "Result of 'Picker <Label, SelectionValue, Content>' initializer is unused"
            ForEach(cateName) { cate in
                Text(cate.cateName ?? "").tag(cate as CateEnt?)
            }
        }
    }
}
...

also added those lines in CatesEnt+ & FilesEnt+CoreDataProperties.swift files:

public var wrappedCateName: String {
    cateName ?? "unknown cates"
}


public var wrappedFileName: String {
    fileName ?? "unknown files"
}
public var wrappedFileCate: String {
    fileCate ?? "unknown files"
    }
public var catesArray: [CatesEnt] {
    let set = cates as? Set<CatesEnt> ?? []
    return set.sorted {
        $0.wrappedCateName < $1.wrappedCateName
    }
}

in another view, user enters cateName values that are shown as a list in the same order in Picker.

I am rockie learning SwiftUI. Thanks for help!

You cannot put view declarations inside closures passed to action methods like onTapGesture. What did you expect by putting a view (Picker) in onTapGesture?

OOPer, try to get the picked value of Picker that is from attribute of CatesEnt, to show on TextField and save into fileCate attribute of FilesEnt. How can I do that? thanks.

cannot modify the original post, so repost the question: how to get the value picked by catePickerView from cateName of CatesEnt entity to be saved in fileCate in FilesEnt entity via a TextField?

HStack { Text("Folder:") TextField("select", text: $fileData.fileCate) catePickerView(cateName: Array(cates), selectedCate: $selectedCate) // catePickerView works fine by itself }

Editing feature is impractically limited in this site. You may need to use Your Answer to add some updates to your original post. And anyway, showing only partial code would not work well to get better responses sooner.

SwiftUI Picker in a TextField with Core Data, error “Result of 'Picker &lt;Label, SelectionValue, Content&gt;' initializer is unused”
 
 
Q