NEW: My new book Pro SwiftUI is out now – level up your SwiftUI skills today! >>

SOLVED: Xcode error

Forums > SwiftUI

Has anyone seen this error and what might cause it?

MessageSendFailure: Message send failure for update

==================================

RemoteHumanReadableError: The operation couldn’t be completed. XPC error received on message reply handler
BSServiceConnectionErrorDomain (3):
==BSErrorCodeDescription: OperationFailed
==NSLocalizedFailureReason: XPC error received on message reply handler

This error appears when I press the Canvas Diagnostics button. I can't figure out what I've done to cause this....

   

Here is the Swift Code that caused the error it was modeled after "Bookworm" Core Data project:

import CoreData
import SwiftUI

struct CustomerDetailView: View {
    let customer: Customer
    @Environment(\.managedObjectContext) var moc
    @Environment(\.dismiss) private var dismiss
    @State private var showingDeleteAlert = false

    var body: some View {

        VStack(alignment: .center, spacing: 5) {

            HStack {
                    Text(self.customer.customerFirstName?.uppercased() ?? "Unknown");Text(self.customer.customerLastName?.uppercased() ?? "Unknown")
                    }
                        .font(.largeTitle)
                        .foregroundColor(.indigo)
                        .padding(8)

            HStack {
                    Text(self.customer.customerAddress1 ?? "Unknown"); Text(self.customer.customerAddress2 ?? "Unknown")
                        }
            HStack {
                Text(self.customer.customerCity ?? "_");Text(self.customer.customerState ?? "Unknown");Text(self.customer.customerZipcode ?? "Unknown");Text(self.customer.customerCountry ?? "Unknown")
            }
            .padding(8)
            HStack {
                Text("Home Phone:");Text(self.customer.customerPhoneNo ?? "Unknown")
            }
            HStack {
                Text("Cell Phone:");Text(self.customer.customerPhoneNo2 ?? "Unknown")
            }
            HStack {
                Text("Email:");Text(self.customer.customerEmail ?? "Unknown")
            }
            VStack {
                Text(self.customer.customerDate?.formatted(date: .complete, time: .standard) ?? "Unknown")
                HStack {
                Text("ReferedBy:");Text(self.customer.customerReferedBy ?? "Unknown")
                }
                HStack{
                Text("Birthday/Anniversary Month:");Text(self.customer.customerBirthdayMonth ?? "Unknown")
                }
            }
            .padding()
            Text(" Notes: ")
                .font(.title2)
            HStack {
                Text(self.customer.customerNotes ?? "Unknown")
            }
            .multilineTextAlignment(.leading)

        }
                Spacer()
        .navigationBarTitle(Text("Customer"), displayMode: .inline)
        .alert(isPresented: $showingDeleteAlert) {
            Alert(title: Text("Delete Customer"), message: Text("Are you sure?"), primaryButton: .destructive(Text("Delete")) {
                    self.deleteCustomer()
                }, secondaryButton: .cancel()
            )
        }
        .navigationBarItems(trailing: Button(action: {
            self.showingDeleteAlert = true
        }) {
            Image(systemName: "trash")
        })
    }

    func deleteCustomer() {
        moc.delete(customer)

        // uncomment this line if you want to make the deletion permanent
        try? self.moc.save()
        dismiss()
    }
}

struct CustomerDetailView_Previews: PreviewProvider {
    static let moc = NSManagedObjectContext(concurrencyType: .mainQueueConcurrencyType)

    static var previews: some View {
        let customer = Customer(context: moc)
        customer.customerID = UUID()
        customer.customerFirstName = "Fred"
        customer.customerLastName = "Flintstone"
        customer.customerAddress1 = "123 2nd Street"
        customer.customerAddress2 = "Apt 3B"
        customer.customerCity = "Bedrock"
        customer.customerState = "Rubble state"
        customer.customerZipcode = "12345"
        customer.customerCountry = "USA"
        customer.customerEmail = "FredFlinstome@bedrock.com"
        customer.customerDate = Date.now
        customer.customerReferedBy = "Wilma"
        customer.customerBirthdayMonth = "March"
        customer.customerNotes = "notes"

      return NavigationView {
            CustomerDetailView(customer: customer)
        }
    }
}

   

This seems totally unnecessary:

    HStack {
        Text("Cell Phone:");Text(self.customer.customerPhoneNo2 ?? "Unknown")
    }

Why? Why are you wrapping a text view in an HStack? HStacks are for, well stacking views next to each other. What are you stacking here?

Clearly this isn't the issue. If you remove all these unnecessary HStacks from your code, you reduce your search by half, or more.

   

Hacking with Swift is sponsored by Play

SPONSORED Play is the first native iOS design tool created for designers and engineers. You can install Play for iOS and iPad today and sign up to check out the Beta of our macOS app with SwiftUI code export. We're also hiring engineers!

Click to learn more about Play!

Sponsor Hacking with Swift and reach the world's largest Swift community!

This error feels like a JAVA error. Are you trying to link your customer to a remote JAVA service?

RemoteHumanReadableError: The operation couldn’t be completed. XPC error received on message reply handler

Keywords here:

  1. Remote
  2. ReadableError
  3. XPC
  4. message reply handler

I don't think @twostraws covered any of these in any CoreData tutorial. I could be wrong. (Often!)

Gut instinct is you are attempting a remote data call and the message reply handler to read your remote data is failing.

1      

Flintstone address

I am pretty sure Fred and WIlma lived on Cobblestone Lane.

   

  1. I agree that the overuse of HStack makes my code messy to say the least, and I'm looking into better ways to get my CustomerDetailView to display better. Strangely this above approach works when compiling to Mac OS, but not on the iPhone as it will not display this View and simpily crashes the app. It does however work flawlessly in the iPhone simulator?? So that is strange as I never had this happen before so its odd behavior.
  2. I am not doing any JAVA code or contact any "services" in my code.
  3. I thought maybe the code in the CustomerDetailView_Preview was causing this but I commented that out and it made no difference.
  4. I should have remembered the Flintstones address as I watched that too much as a child...but thought this was only there to make the Preview function perhaps I was incorrect in that thought.
  5. I did go back to GitHub and downloaded Paul's Bookworm project and got a similar crash on the detail view in it?? Which makes me wonder if my version of Xcode may have got corrupted?? I have another machine I can test the code on... so thats another trail to follow. I am running Xcode version 13.2.1 so perhaps its buggy??

Thanks for the responce, I will keep looking into this and update if I find a solution.

   

Hmm. Weird. Post a screen shot of your entitlements file and your "signing and capabilities" screen in xcode. I agree that this seems to be an issue with something trying to reach out and touch something that either isn't at the end point, or isn't responding in an expected manner. That's how it seems. Things aren't always as they seem, but the #1 skill in software development is a thorough understanding of logic flow and diagnostics theory.

You may have inadvertantly brought in a dependency or turned on a remote feature without consciously meaning to do so. I'm probably unfairly making an assumption about your level of experience with Apple development and with using XCode, so apologies if it seems like I'm sending you back to square 1. Again, diagnostics theory. It's what I do. :)

Do you have icloud syncing on, are you using syncing with core data, are you logged into icloud on the device/simulator if so, and a host of other questions come to mind. I don't know that your XCode installation is corrupted, but a quick check to see if your project files have gone off a bit is to create a new project, basic template thing, run it... then start transplanting your code files into it, cleaning, building, and running it along the way, and see what results you get.

I'd suggest doing so regardless of your efforts downloading and re-running Paul's project.

   

I looked at my entitlements file and it only shows one entilement file: App Sandbox Type: Boolean and Value = Yes

I tryed creating a new project file just to see what shows up under entilements with a "clean and empty" file.

It shows two entitlements: App Sandbox Type: Boolean and Value = Yes com.apple.security.filesuser-selected.read-only Type: Boolean Value: 1

So that created more questions.

I'm not doing iCloud syncing as when I created the project I didn't check the add CoreData and or the iCloud syncing check boxes.

I added the .xcdatamodeld in myself and copied over the DataController.swift file from the Bookworm project.

The only thing Network related on the Signings & Capabilities was outgoing Connections (Client) that was checked under the App Sandbox. But when I do the new project it is checked as well. Is this correct?

1      

Sounds right. Hmm.... I'll go off and ponder.

   

So this discussion begs the question is there a "course/video/source" online that covers the Xcode app only. I've looked around Apple's developer site and either missed it or there isn't one. I'm looking for how to use it, what all the settings are, pitfalls, do's, don'ts. From a complete newbie to programming of any kind perspective it can be a little overwhelming.

   

I moved the project to another computer and ran it again, strange behavior still happens will compile and run on my iPad (3rd generation 12.9 iPad Pro) but on my iPhone 11 Pro Max it will compile load on phone but when I try to use the app it freezes and crashes on iPhone??

  1. So its not Xcode on the laptop causing the issue.
  2. It seems to be related to building on my iPhone.

I did notice a Thread error : Thread 1: EXC_BAD_ACCESS (code=1, address=0x1dfd85298) . Which I might have missed earlier.

So not sure what that is and what I did that caused it. But I'm sure I'm guilty of doing something wrong... :)

   

I have found a fix that allows the code to function on my iPhone. Simply moving the .navigationBarItems just outside the NavigationView let the app compile and run on the iPhone? This code was in a different "CustomerView" and effected the use of the DetailView...

   

regarding the overuse of HStack

You can add \( ) inside a Text() to process any code like so:

    Text("Cell Phone: \(self.customer.customerPhoneNo2 ?? "Unknown")")

   

I have had the same problem.

Recipe:

  1. Go to your data model file.
  2. Click "Default" under configurations.
  3. Open the Inspector (top right button in corner).
  4. Under "File Inspector" (the tab with the file icon), it should mention the "Full Path". The last two paths "".xcdatamodeld and "".xcdatamodel should have the same name before the full stops. Copy one of those names.
  5. Go to "Persistence.swift", under the init function there should be this line of code:

    container = NSPersistentContainer(name: "name")

    Change the name inside the quotation marks to the name that you copied from the file path.

If this doesn't work, make sure your persistence.swift, any file that uses a @fetchrequest, accesses .managedObjectContext or accesses PersistenceController.shared, is referencing the correct swift files, project and app throughout.

   

Hacking with Swift is sponsored by Play

SPONSORED Play is the first native iOS design tool created for designers and engineers. You can install Play for iOS and iPad today and sign up to check out the Beta of our macOS app with SwiftUI code export. We're also hiring engineers!

Click to learn more about Play!

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.