Cannot assign to property is a get-only property

I have been stuck on this problem for days and I have scoured the Internet, yet none of the solutions I’ve seen seem to help. Any help would be appreciated. I can create a new Core Data Entity and save everything to it just fine. I can also display the contents just fine. The problem comes in my update details screen. It won’t let me put the entity attributes in a TextField or save anything and gives me this error. I was wondering if someone could give me insight in general as to why this error possibly would show up on a core data attribute. I have seen where it could have something to do with whether the attribute is optional or not, but changes that doesn’t seem to make any difference. I’m new to swift and definitely to core data. The two tutorials on here didn’t do any updates, unfortunately.

Is your project in SwiftUI or UIKit? (They each interact with Core Data differently)

Can you show the code you have for setting the TextField?

Paste your code in as text, rather than providing a screenshot.

To format the code nicely, place 3 back-ticks ``` on the line above your code and 3 back-ticks ``` on the line below your code. The 3 back-ticks must be the ONLY characters on the line. The back-tick character is located on the same keyboard key as the tilde character ~ (which is located below the Esc key on a US keyboard). You can also highlight an entire code block and click the </> button on the toolbar to wrap the block for you.

This also makes it easier for anyone assisting as they can copy the code and carry out some testing.

Thanks for responding Mikeala. It is in SwiftUI. I will do my best to post the code as you’ve asked. Honestly I have stripped it down to bare bones at this point, but I will attempt to display what I have as soon as I can.

import SwiftUI

struct CodeSnippets: View {

//This is what my CaseNumberEntity looks like in CoreData
// extension CaseNumberEntity {
//
// @nonobjc public class func fetchRequest() → NSFetchRequest {
// return NSFetchRequest(entityName: “CaseNumberEntity”)
// }
//
// @NSManaged public var id: UUID?
// @NSManaged public var number: String?
// @NSManaged public var cases: NSSet?
// @NSManaged public var date: CourtDateEntity?
//
// public var wrappedCaseNumber: String {
// number ?? “Unknown Case Number”
// }
//
// public var caseArray: [CaseEntity] {
// let set = cases as? Set ??
//
// return set.sorted {
// $0.wrappedCaseName < $1.wrappedCaseName
// }
// }
//
// }

//This is partially what my CaseEntity looks like in //CoreData.
//I have code to create array from the NSSet? vars, but //they seem to be working fine.
//
// extension CaseEntity {
//
// @nonobjc public class func fetchRequest() → NSFetchRequest {
// return NSFetchRequest(entityName: “CaseEntity”)
// }
//
// @NSManaged public var evidenceDotCom: Bool
// @NSManaged public var id: UUID?
// @NSManaged public var name: String?
// @NSManaged public var sharedWithCWA: Bool
// @NSManaged public var extratasks: NSSet?
// @NSManaged public var fcpdcase: CaseNumberEntity?
// @NSManaged public var orders: NSSet?
// @NSManaged public var supoenas: NSSet?
// @NSManaged public var videoclips: NSSet?
// @NSManaged public var warrants: NSSet?
//
// public var wrappedCaseName: String {
// name ?? “Unknown Case Name”
//
// }

@FetchRequest(sortDescriptors: [NSSortDescriptor(key: "number", ascending: true)]) var caseNumbers: FetchedResults<CaseNumberEntity>

//passed in from PendingCaseListView
var selectedCaseNumberEntity: CaseNumberEntity

@State private var showCaseDataSheet = false


var body: some View {
    VStack{

//cycle through and display all case numbers so he can
//choose the one he wants to update
ForEach(selectedCaseNumberEntity.caseArray) {
selectedCaseEntity in

            Button(action: {
                showCaseDataSheet.toggle()
                
            }, label: {
                     
            Text(selectedCaseEntity.wrappedCaseName)
              .padding(15)
              .foregroundColor(.black.opacity(0.7))
              .background(Color.blue.opacity(0.3))
              .cornerRadius(30)
              .padding(30)
              .shadow(color: .black.opacity(0.3),   
                                 radius: 3, x: 3, y: 3)
            })
            .sheet(isPresented: $showCaseDataSheet){

UpdateCaseInfoSheet(passedCaseEntity:selectedCaseEntity)

            }//end sheet
            
            
        }//end ForEach
    }//end VStack
    
}//end body

}//end View

struct UpdateCaseInfoSheet: View {

@ObservedObject var passedCaseEntity: CaseEntity

var body: some View {
    
    TextField("Case Identifier", text: $passedCaseEntity.wrappedCaseName) //<------------here is where I get the error Cannot assign to property: 'wrappedCaseName' is a get-only property
    

}

}




Sorry the code looks all broken up like this. I’m not sure exactly what I did wrong.

You should write 3 backticks at the start of your code block, and 3 at the end. With the backticks on its own line, that’ll format it properly

I solved my problem at long last…

@StateObject var passedCaseEntity: CaseEntity
@State private var caseName

TextField("\(passedCaseEntity.wrappedCaseName)", text: $caseName)
            Button ("Update") {
                if !caseName.isEmpty {
                    passedCaseEntity.name! = caseName
                }
            }