I have two views here: RoomDetailView and FeaturedTabView
In the FeaturedTabView, there are two variables imageString and roomImages, the imageString will receive data from RoomDetailView as parameter and RoomImages is for storing an array which is split from imageString after the imageString is assigned with the string coming from RoomDetailView.
I have two questions here:
My app keep crashing and return error: terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Room roomImages]: unrecognized selector sent to instance 0x6000027f1ea0'. However, I am pretty sure that my variable type is correct and is aligned with my coreData attribute type.
May I ask is there anywhere I can first process the string, split to array ( try using init but I dont think that is the correct way to go ) and assign to another roomImages variable before the view get rendered.
struct RoomDetailView: View { let room: Room; var body: some View { ZStack{ VStack(spacing: 0){ FeaturedTabView(imageString: room.roomImages ?? "room-1,") .padding(.vertical, 20) }) } .background(Color.white.ignoresSafeArea(.all, edges: .all)) } .ignoresSafeArea(.all, edges: .top) } } struct FeaturedTabView: View { let imageString: String let roomImages: [String] var body: some View { TabView{ ForEach(imageString, id: \.self){ img in FeaturedItemView(img: img) .padding(.top, 10) .padding(.horizontal, 15) } } .tabViewStyle(PageTabViewStyle(indexDisplayMode: .always)) } init(imageString: String){ self.imageString = imageString self.roomImages = self.imageString.components(separatedBy: ",") }}