0

This is my data model inside a structure. There is an array with 15 up to 30 elements, depending on the situation. It is an array of tuples and that has its disadvantages. What is the cleanest way to rewrite my datamodel? And what are advantages and disadvantages?

import SwiftUI
import Combine
import Foundation

struct Egg: Identifiable {

    typealias EggDay = (day: Int, mW: Double, measured: Bool, daily: Double)

    let id: Int
    let taxonomy: String
    let species: String
    let layDate: Date
    let daysToPip: Int
    let daysToHatch: Int
    let weightLossMin : Int
    let weightLossMax: Int
    let temperature: Double
    let humidity: Double
    let actualWeights : [EggDay]
}

In my app I work with an array of Eggs, mainly to have a List with eggs to be able to select one. And then the selected egg displays all days to edit/add measurements.

1 Answer 1

1

The main disadvantage of the tuple in your case is tuples can not conform protocols like Identifiable.

Another one is that you can change struct to class to make your eggs reference type later, but it's hard for doing that for a tuple and needs lots of changes.

Note: Almost all iOS frameworks contains Foundation, don't import it again.

Sign up to request clarification or add additional context in comments.

4 Comments

Hi Mojtaba, what is the alternative? Guess making 4 different arrays is the easiest? You're right with reference type, that is a big advantage using SwiftUI.
Alternative to what? You can use any structure you like.
Who wants to use a tuple not a struct ? @MichaelSalmon
So why are you post comment under this answer @MichaelSalmon? :) You should comment below the original question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.