Search in object array in Swift : <p>I have code:</p>

<pre><code>func getDataToProductView(){
        let documentsDir = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
        let path = documentsDir.appendingPathComponent((AppGlobalManager.sharedManager.loggedUser?.selectedLanguage)! + "/json/products.json")
        do {
            let data = try Data(contentsOf: path)
            let decoder = JSONDecoder()
            let productsTmpObjectArray = try decoder.decode([Products].self, from: data)

            productCount.text = String(productsObjectArray.count)

        } catch {
            print("ProductViewControler - Error 102: Problem with parse file. \(error)")
        }
    }

struct ProductObject : Codable {
    let palletHeight : Double?
    let layerPallet : Int?
    let prepCombisteamer : String?
    let id : Int?
    let temporaryWorlds : [String]?
    let temporarySegments : [String]?
    let sunFlower : Bool?
    let inPieces : Bool?
    let noBox : Int?
    let prepFryingPan : String?
    let packageContents : Double?
    let carbohydrates : Double?
    let eanBox : String? // Int
    let kcal : Int?
    let markedAsFavourite1 : Bool?
    let temporaryPodSegmentyRynku : [String]?
    let prepPot : String?
    let prepMicrowave : String?
    let boxLayer : Int?
    let code : String? // Int
    let prepDeepFryer : String?
    let name : String?
    let temporaryConcepts : [String]?
    let active : Bool?
    let temporarySegmentyRynku : [String]?
    let shelfLifeTimeFrame : String?
    let changeTime : ChangeTime?
    let palletWeight : Double?
    let markedAsFavourite2 : Bool?
    let kj : Int?
    let langVersions : [LangVersions]?
    let proteins : Double? // Int
    let regions : [Int]?
    let containsGluten : Bool?
    let markedAsFavourite3 : Bool?
    let eanFoil : String? // Int
    let shelfLife : String? // Int
    let contentPerBox : Int?
    let prepOven : String?
}
</code></pre>

<p>and sample object:</p>

<pre><code>{
    "palletHeight": 190,
    "layerPallet": 6,
    "prepCombisteamer": "10-15 min / 220C",
    "id": 152,
    "temporaryWorlds": [
      "ALWAYS_EVERYWHERE"
    ],
    "temporarySegments": [
      "FRIES"
    ],
    "sunFlower": false,
    "inPieces": false,
    "noBox": 54,
    "prepFryingPan": "",
    "packageContents": 2.5,
    "carbohydrates": 24.5,
    "fat": 4,
    "eanBox": "8710449999194",
    "kcal": 150,
    "markedAsFavourite1": false,
    "temporaryPodSegmentyRynku": [
      "DANIE_GLOWNE",
      "BUFET"
    ],
    "prepPot": "",
    "prepMicrowave": "",
    "boxLayer": 9,
    "code": "302503",
    "prepDeepFryer": "3-3,5 min / 175C",
    "name": "CLASSIC Oven Fries 10 mm",
    "temporaryConcepts": [
      "MIX_TO_GO",
      "SHARE_THE_FUN"
    ],
    "active": true,
    "temporarySegmentyRynku": [
      "KANTYNA_CATERING",
      "HOTEL"
    ],
    "shelfLifeTimeFrame": "MONTHS",
    "changeTime": {
      "dayOfMonth": 6,
      "minute": 44,
      "second": 41,
      "year": 2017,
      "month": 3,
      "hourOfDay": 10
    },
</code></pre>

<p>I would like to search in my array productsTmpObjectArray objects all objects that:</p>

<pre><code>a) temporaryPodSegmentyRynku == DANIE_GLOWNE
b) temporaryConcepts = SHARE_THE_FUN
c) temporarySegmentyRynku = HOTEL
d) fat = 8
</code></pre>

<p>Does anyone know how to do it?</p>

<p>I thing about something like this:</p>

<pre><code>func productsFilter1(array: [Products])-&gt; [Products]{
        var tmpProductsArray = [Products]()
        for product in array{
            if product.fat == 8 {
                tmpProductsArray.append(Products(id: product.id, active: product.active, regions:product.regions, code: product.code, eanFoil: product.eanFoil, eanBox: product.eanBox, noBox: product.noBox, layerPallet: product.layerPallet, boxLayer: product.boxLayer, palletWeight: product.palletWeight, palletHeight: product.palletHeight, packageContents: product.packageContents, contentPerBox: product.contentPerBox, name: product.name, inPieces: product.inPieces, prepDeepFryer: product.prepDeepFryer, prepOven: product.prepOven, prepCombisteamer: product.prepCombisteamer, prepFryingPan: product.prepFryingPan, prepPot: product.prepPot, prepMicrowave: product.prepMicrowave, shelfLife: product.shelfLife, shelfLifeTimeFrame: product.shelfLifeTimeFrame, kj: product.kj, kcal: product.kcal, proteins: product.proteins, carbohydrates: product.carbohydrates, fat: product.fat, sunFlower: product.sunFlower, containsGluten: product.containsGluten, pieceWeight: product.pieceWeight, numberOfPiecesInPackage: product.numberOfPiecesInPackage, temporaryWorlds: product.temporaryWorlds, temporaryConcepts: product.temporaryConcepts, temporarySegments: product.temporarySegments, temporaryPodSegmentyRynku: product.temporaryPodSegmentyRynku, temporarySegmentyRynku: product.temporarySegmentyRynku, langVersions: product.langVersions, changeTime: product.changeTime, markedAsFavourite1: product.markedAsFavourite1, markedAsFavourite2: product.markedAsFavourite2, markedAsFavourite3: product.markedAsFavourite3))
            }
        }
        return tmpProductsArray
    }
</code></pre>

<p>Would this solution be ok?
For points: a, b, c, it's best to do separate search functions?
How do you do a search for points a, b and c?</p>
