Xcode Build Failure

Hi, I don't understand why Xcode fails to build my app when following logic was uncommented as part of ternary operator (as highlighted in attachment). Can somebody help me please ?? Thx.

...

: shelterViewModel.getShelter(row: row, column: column).productId == ...
   ? Color.yellow

...

The error: The compiler is unable to type-check the expression in real-time generally means you're trying to do too many things in one place, and you should break it down a little.

Firstly, to make it more readable, I'd put brackets around each ternary expression, for example: (row %2 == 0 ? Color.blue : Color.orange) so you can see which bits are enclosed.

Then I'd split it out like this, creating a let for the various bits so they're individually evaluated prior to the larger expression. Also, I'd indent the code so it's more readable, putting the positive on the first line, and the negative on the next line, indented:

let borderColor1 = (row %2 == 0 ? Color.blue : Color.orange)
let borderColor2 = (shelterViewModel.getShelter(row: row, column: column).productId = ViewConstants.LAYOUT_DUMMY_ID ? Color.yellow : Color.green)

.border(
	(shelterViewModel.getShelter0perationFormat() ? borderColor1
			: (locationViewModel.getLocation(row: row, column: column) ? Color.red
				: borderColor2)),
	width: 0.5 //(self.interfaceLayout == ViewConstants.BACKEND_OPERATION ? 0.5 : 0.5)
)

Finally, this bit at the end is pointless as the two values are the same: width: (self.interfaceLayout == ViewConstants.BACKEND_OPERATION ? 0.5 : 0.5) so you can replace it with 0.5, unless you're going to change one of those values?

May be because image is upside down 😉

When you post a message, make it easy to use:

  • image in correct orientation
  • complete code so that one can test, in text, not only screenshot
  • full error message

Seems it is a problem to type check

shelterViewModel.getShelter (row: row, column: column).productId == ViewConstants.LAYOUT_DUMMY_
  • what is productId type ?
  • How are ViewConstants defined ?
  • What is .LAYOUT_DUMMY_ ? Which type ? If it is not exactly the same as productId, then the error.

Note: tests as

shelterViewModel.getShelterOperationFormat() != true

may be written

!shelterViewModel.getShelterOperationFormat()

@darkpaw:

I have included snippet of my code below as reference.

The 'width' parameter can be changed later ...

However, same error would still show up:

"The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions"

...

struct ViewShelter: View {
// TH: helps safely update UI.
@State private var rowEven: Bool = true
@State private var pathBlocked: Bool = true
@State private var borderColorBackEnd: Color = Color.black
@State private var borderColorBackEndOperation: Color = Color.black

var body: some View {
    VStack (alignment: .leading){
        ForEach(0...(ViewConstants.TARGET_STRING_BACK_0_DIMENSION-1), id:\.self) { row in
            if let row_x = shelterViewModel.getShelter(row: row) as [RecommendationEntity]? {
                if let row_x_count = row_x.count as Int? {
                    if row_x_count > 0 {
                        let row_x_columns = Array(0...row_x_count-1)
                        GeometryReader { geometry in
                            HStack(alignment: .center) {
                                ForEach(row_x_columns, id:\.self){ column in
                                    
                                    self.rowEven     = (row%2==0)
                                    self.pathBlocked = (shelterViewModel.getShelter(row: row, column: column).productId == ViewConstants.LAYOUT_DUMMY_ID_PRODUCT)
                                    
                                    self.borderColorBackEnd          = (rowEven     ? Color.blue   : Color.orange)
                                    self.borderColorBackEndOperation = (pathBlocked ? Color.yellow : Color.green)
                                    
                                    VStack{ … }
                                    .border(
                                        
                                        (shelterViewModel.getShelterOperationFormat() != true) ? borderColorBackEnd
                                          : (locationViewModel.getLocation(row: row, column: column) == true) ? Color.red
                                            : borderColorBackEndOperation,
                                        width: self.interfaceLayout == ViewConstants.BACKEND_OPERATION ? 0.5 : 0.5
                                        
                                    )
                                    .onTapGesture { … }
                                }//ForEach.
                            }//HStack.
                        }//GeometryReader.
                        .frame( … )
                    }// if count > 0.
                }//if row_x_count.
            }//if row_x.
        }//ForEach.
    }//VStack.
}//body: View.

@Claude31:

Sorry about image orientation, looks like a Mac or Web thing ... either way, I don't know what happened during upload.

I will post code, instead of or possibly along with screenshot.

I will post full error message, if one shows up.

Variables are defined, as follows:

struct RecommendationEntity: Decodable, Identifiable, Hashable {

var productId: Int64

}

enum ViewConstants {

static let LAYOUT_DUMMY_ID_PRODUCT = 1

}

Hi,

Does anybody know how I can escalate this issue to the Apple's technical support engineer please ??

Maybe, I am making a mistake here and there.

However, I think that it looks like this is a tool issue ...

Thx,

TH

Hi everybody,

May I ask ??

  • if anybody knows how I could get official Apple technical support on a mobile app I have been trying to develop please. I am willing to go in person to Cupertino for direct contact, if necessary.

Basically, I am trying to develop an indoor/outdoor navigation app with following components:

  • front-end consumer: submits online order via their smart phone.
  • middle-end user: retrieves items from storage and delivers items to consumers.
  • back-end user: organizes and maintains inventory.

I could provide more details upon further request. My direct contact is: 208-371-3769.

Thank you, Have a nice day, TH

Xcode Build Failure
 
 
Q