Reputation:
The values of my coredata entity Order
is stored in orderDetails
. orderDetails
has a count of 8 and it has columns like orderId
, remaining Balance
and deliveryType
. The column deliveryType
has values Payment Pending
, Delivery Pending
etc. There are 2 entries having Payment Pending
. And I want to get these two entries and their values of orderId
and remaining Balance
.
In viewWillAppear
I’m doing this…
for result in orderDetails {
if let delType = result.value(forKey: "deliveryType") as? NSString {
if delType == "Payment Pending" {
}
}
}
This just takes me to that entry having value “Payment Pending
”. But how do I proceed further.. I mean how can I give the count in numberOfRowsInSection
and assign the proper values in cellForRowAt
..
Upvotes: 1
Views: 42
Reputation: 2678
Instead of your for loop, use this code :-
let paymentPendingData = orderDetails.filter{ ($0.deliveryType ?? "").lowercased() == "payment pending" }
This will filter the payment pending data from your orderDetails and store to the array paymentPendingData which again is an array of type Order. You can use the count of that array.
Upvotes: 1