matching list specs

Hello, I am a beginner on swiftUI and I would like to match a 2 elements of a list according to their location ("place" in my code). I'm trying to make a home automation application, so when we add a device by giving it its location (in deviceList), it will be assigned to the desired room. I tried to put : if room.place == device.place {at different location but it doesn't work. I put you some pictures without theif to understand: [ListView] (https://i.stack.imgur.com/zzSZz.png) [DeviceView] (https://i.stack.imgur.com/Mn6Am.png) [RoomView] (https://i.stack.imgur.com/Q5w8y.png) Thanks

Welcome to the forum.

Please show the code you have so far as text, not simply as screenshots. And explain where you tried the match and what does not work (compiler error ? incorrect result ?)

Please also explain what you mean by "trying to match 2 elements".

  • Do you want to find elements that are at the same location ?
  • If so, what do you want to do with this match ?
  • Do you want to show in RoomView all devices in the room ?

If so, you should try this in RoomView, line 37:

ForEach(deviceList, id: \.name) { device in
  if device.place == room.place {
     CellView(device: device
  }
}

Note also that struct names should start with Uppercase, but var (as roomList) should start with lowercase.

matching list specs
 
 
Q