above image I got the set of dictionary values, there is an key “CustNo” had 10 different value, I need to display the values in tableview label , tried but the last element is replacing the all values.
Welcome to the community.
Would you paste the entire dictionary in a reply as text please.
When you have pasted it in, can you select it all with your cursor and tap the icon that looks like this </>
which will format the text nicely and preserves any embedded quotes as a quotes rather than them being converting into unicode characters by the forum post which is a hassle.
This will make is easier to do some testing on it.
sure! my dictionary syntax is var listValues: Dictionary<String,String> = Dictionary<String, String>()
I mean can you post the dictionary data in a reply. It’s difficult to come up with any suggestions by trying to look at an image.
rtn is query, iterating the queryValues
for (index,element) in rtn.enumerated() {
print(“ListElements(index), (element)”)
}
outPut:
ListElements0, [“Phone”: “”, “PriceGroup”: “”, “CustNo”: “2018002494”, “CustomerName”: “2 JS - ABATAN", "SearchName": "2 J
S - ABATAN”, “longitude”: “0.0”, “latitude”: “0”, “AgentID”: “GBIBAG VAN MT. PROVINCE”, “ChineseName”: “2 J`S - ABATAN”, “Address”: “LOO, ABATAN”, “CreditLimit”: “0.0”, “Contact”: “”]
ListElements1, [“Phone”: “”, “PriceGroup”: “”, “CustNo”: “2018002495”, “CustomerName”: “3J CALIKING”, “SearchName”: “3J CALIKING”, “longitude”: “120.8216937”, “latitude”: “16.80337503”, “AgentID”: “GBIBAG VAN MT. PROVINCE”, “ChineseName”: “3J CALIKING”, “Address”: “CALIKING”, “CreditLimit”: “0.0”, “Contact”: “”]
ListElements2, [“Phone”: “”, “PriceGroup”: “0”, “CustNo”: “2018002496”, “CustomerName”: “4J”, “SearchName”: “4J”, “longitude”: “0.0”, “latitude”: “0”, “AgentID”: “GBIBAG VAN MT. PROVINCE”, “ChineseName”: “4J”, “Address”: “BESAO. MT. PROVINCE”, “CreditLimit”: “0.0”, “Contact”: “”]
ListElements3, [“Phone”: “”, “PriceGroup”: “”, “CustNo”: “2018002497”, “CustomerName”: “7J”, “SearchName”: “7J”, “longitude”: “0.0”, “latitude”: “0”, “AgentID”: “GBIBAG VAN MT. PROVINCE”, “ChineseName”: “7J”, “Address”: “SAGADA”, “CreditLimit”: “0.0”, “Contact”: “”]
ListElements4, [“Phone”: “”, “PriceGroup”: “”, “CustNo”: “2018002498”, “CustomerName”: “7J”, “SearchName”: “7J”, “longitude”: “0.0”, “latitude”: “0”, “AgentID”: “GBIBAG VAN MT. PROVINCE”, “ChineseName”: “7J”, “Address”: “SAGADA”, “CreditLimit”: “0.0”, “Contact”: “”]
ListElements5, [“Phone”: “”, “PriceGroup”: “”, “CustNo”: “2018002499”, “CustomerName”: “97 BUY”, “SearchName”: “97 BUY”, “longitude”: “0.0”, “latitude”: “0”, “AgentID”: “GBIBAG VAN MT. PROVINCE”, “ChineseName”: “97 BUY”, “Address”: “SAGADA”, “CreditLimit”: “0.0”, “Contact”: “”]
ListElements6, [“Phone”: “”, “PriceGroup”: “0”, “CustNo”: “2018002500”, “CustomerName”: “A & J”, “SearchName”: “A & J”, “longitude”: “0.0”, “latitude”: “0”, “AgentID”: “GBIBAG VAN MT. PROVINCE”, “ChineseName”: “A & J”, “Address”: “LOO, ABATAN”, “CreditLimit”: “0.0”, “Contact”: “”]
ListElements7, [“Phone”: “”, “PriceGroup”: “”, “CustNo”: “2018002501”, “CustomerName”: “ABATAN PHARMACY”, “SearchName”: “ABATAN PHARMACY”, “longitude”: “0.0”, “latitude”: “0”, “AgentID”: “GBIBAG VAN MT. PROVINCE”, “ChineseName”: “ABATAN PHARMACY”, “Address”: “ABATAN”, “CreditLimit”: “0.0”, “Contact”: “”]
ListElements8, [“Phone”: “”, “PriceGroup”: “”, “CustNo”: “2018002502”, “CustomerName”: “ABC”, “SearchName”: “ABC”, “longitude”: “120.8209413”, “latitude”: “16.8043892”, “AgentID”: “GBIBAG VAN MT. PROVINCE”, “ChineseName”: “ABC”, “Address”: “BESAO. MT. PROVINCE”, “CreditLimit”: “0.0”, “Contact”: “”]
ListElements9, [“Phone”: “”, “PriceGroup”: “”, “CustNo”: “2018002503”, “CustomerName”: “ABENT”, “SearchName”: “ABENT”, “longitude”: “0.0”, “latitude”: “0”, “AgentID”: “GBIBAG VAN MT. PROVINCE”, “ChineseName”: “ABENT”, “Address”: “COTCOT”, “CreditLimit”: “0.0”, “Contact”: “”]
OK that’s a good start. Where is the data coming from? Is it public and do you have a URL that is the source of it?
Have you defined a data model which describes a single element of that data? Essentially what you need to do is loop through each record and extract each dictionary item into a corresponding property that is defined in a struct or a class.
Does that make sense?
above output there is CustNo and it has values each elements and my output is need to be
single key multiple values
For Example,
CustNo - is key
value is need to be - [ 2018002494 2018002495 2018002496 2018002497 2018002498 2018002499 2018002500 201800250120180025022018002503]
how to bring this OutPut
any sample code similar to what I’m asking?
Are you able to send me the raw data that is in rtn
?
@Chris_Parker here is raw data what I get in rtn
RTN Values [[“Phone”: “”, “Contact”: “”, “SearchName”: “2 JS - ABATAN", "CreditLimit": "0.0", "latitude": "0", "ChineseName": "2 J
S - ABATAN”, “CustNo”: “2018002494”, “Address”: “LOO, ABATAN”, “AgentID”: “GBIBAG VAN MT. PROVINCE”, “longitude”: “0.0”, “PriceGroup”: “”, “CustomerName”: “2 J`S - ABATAN”], [“Phone”: “”, “Contact”: “”, “SearchName”: “3J CALIKING”, “CreditLimit”: “0.0”, “latitude”: “16.80337503”, “ChineseName”: “3J CALIKING”, “CustNo”: “2018002495”, “Address”: “CALIKING”, “AgentID”: “GBIBAG VAN MT. PROVINCE”, “longitude”: “120.8216937”, “PriceGroup”: “”, “CustomerName”: “3J CALIKING”], [“Phone”: “”, “Contact”: “”, “SearchName”: “4J”, “CreditLimit”: “0.0”, “latitude”: “0”, “ChineseName”: “4J”, “CustNo”: “2018002496”, “Address”: “BESAO. MT. PROVINCE”, “AgentID”: “GBIBAG VAN MT. PROVINCE”, “longitude”: “0.0”, “PriceGroup”: “0”, “CustomerName”: “4J”], [“Phone”: “”, “Contact”: “”, “SearchName”: “7J”, “CreditLimit”: “0.0”, “latitude”: “0”, “ChineseName”: “7J”, “CustNo”: “2018002497”, “Address”: “SAGADA”, “AgentID”: “GBIBAG VAN MT. PROVINCE”, “longitude”: “0.0”, “PriceGroup”: “”, “CustomerName”: “7J”], [“Phone”: “”, “Contact”: “”, “SearchName”: “7J”, “CreditLimit”: “0.0”, “latitude”: “0”, “ChineseName”: “7J”, “CustNo”: “2018002498”, “Address”: “SAGADA”, “AgentID”: “GBIBAG VAN MT. PROVINCE”, “longitude”: “0.0”, “PriceGroup”: “”, “CustomerName”: “7J”], [“Phone”: “”, “Contact”: “”, “SearchName”: “97 BUY”, “CreditLimit”: “0.0”, “latitude”: “0”, “ChineseName”: “97 BUY”, “CustNo”: “2018002499”, “Address”: “SAGADA”, “AgentID”: “GBIBAG VAN MT. PROVINCE”, “longitude”: “0.0”, “PriceGroup”: “”, “CustomerName”: “97 BUY”], [“Phone”: “”, “Contact”: “”, “SearchName”: “A & J”, “CreditLimit”: “0.0”, “latitude”: “0”, “ChineseName”: “A & J”, “CustNo”: “2018002500”, “Address”: “LOO, ABATAN”, “AgentID”: “GBIBAG VAN MT. PROVINCE”, “longitude”: “0.0”, “PriceGroup”: “0”, “CustomerName”: “A & J”], [“Phone”: “”, “Contact”: “”, “SearchName”: “ABATAN PHARMACY”, “CreditLimit”: “0.0”, “latitude”: “0”, “ChineseName”: “ABATAN PHARMACY”, “CustNo”: “2018002501”, “Address”: “ABATAN”, “AgentID”: “GBIBAG VAN MT. PROVINCE”, “longitude”: “0.0”, “PriceGroup”: “”, “CustomerName”: “ABATAN PHARMACY”], [“Phone”: “”, “Contact”: “”, “SearchName”: “ABC”, “CreditLimit”: “0.0”, “latitude”: “16.8043892”, “ChineseName”: “ABC”, “CustNo”: “2018002502”, “Address”: “BESAO. MT. PROVINCE”, “AgentID”: “GBIBAG VAN MT. PROVINCE”, “longitude”: “120.8209413”, “PriceGroup”: “”, “CustomerName”: “ABC”], [“Phone”: “”, “Contact”: “”, “SearchName”: “ABENT”, “CreditLimit”: “0.0”, “latitude”: “0”, “ChineseName”: “ABENT”, “CustNo”: “2018002503”, “Address”: “COTCOT”, “AgentID”: “GBIBAG VAN MT. PROVINCE”, “longitude”: “0.0”, “PriceGroup”: “”, “CustomerName”: “ABENT”]]
Ah that’s superb.
Let me get some code organised to extract each CustNo from that.
I hope this code makes sense to you.
If you place all this into a Playground file you can see what it does.
The code extracts each CustNo and appends the value to an array of customerNumbers which are Integers.
I am assuming that is all you wanted to do?
let rtn = [
["Phone": "", "Contact": "", "SearchName": "2 JS - ABATAN", "CreditLimit": "0.0", "latitude": "0", "ChineseName": "2 JS - ABATAN", "CustNo": "2018002494", "Address": "LOO, ABATAN", "AgentID": "GBIBAG VAN MT. PROVINCE", "longitude": "0.0", "PriceGroup": "", "CustomerName": "2 J`S - ABATAN"],
["Phone": "", "Contact": "", "SearchName": "3J CALIKING", "CreditLimit": "0.0", "latitude": "16.80337503", "ChineseName": "3J CALIKING", "CustNo": "2018002495", "Address": "CALIKING", "AgentID": "GBIBAG VAN MT. PROVINCE", "longitude": "120.8216937", "PriceGroup": "", "CustomerName": "3J CALIKING"],
["Phone": "", "Contact": "", "SearchName": "4J", "CreditLimit": "0.0", "latitude": "0", "ChineseName": "4J", "CustNo": "2018002496", "Address": "BESAO. MT. PROVINCE", "AgentID": "GBIBAG VAN MT. PROVINCE", "longitude": "0.0", "PriceGroup": "0", "CustomerName": "4J"],
["Phone": "", "Contact": "", "SearchName": "7J", "CreditLimit": "0.0", "latitude": "0", "ChineseName": "7J", "CustNo": "2018002497", "Address": "SAGADA", "AgentID": "GBIBAG VAN MT. PROVINCE", "longitude": "0.0", "PriceGroup": "", "CustomerName": "7J"],
["Phone": "", "Contact": "", "SearchName": "7J", "CreditLimit": "0.0", "latitude": "0", "ChineseName": "7J", "CustNo": "2018002498", "Address": "SAGADA", "AgentID": "GBIBAG VAN MT. PROVINCE", "longitude": "0.0", "PriceGroup": "", "CustomerName": "7J"],
["Phone": "", "Contact": "", "SearchName": "97 BUY", "CreditLimit": "0.0", "latitude": "0", "ChineseName": "97 BUY", "CustNo": "2018002499", "Address": "SAGADA", "AgentID": "GBIBAG VAN MT. PROVINCE", "longitude": "0.0", "PriceGroup": "", "CustomerName": "97 BUY"],
["Phone": "", "Contact": "", "SearchName": "A & J", "CreditLimit": "0.0", "latitude": "0", "ChineseName": "A & J", "CustNo": "2018002500", "Address": "LOO, ABATAN", "AgentID": "GBIBAG VAN MT. PROVINCE", "longitude": "0.0", "PriceGroup": "0", "CustomerName": "A & J"],
["Phone": "", "Contact": "", "SearchName": "ABATAN PHARMACY", "CreditLimit": "0.0", "latitude": "0", "ChineseName": "ABATAN PHARMACY", "CustNo": "2018002501", "Address": "ABATAN", "AgentID": "GBIBAG VAN MT. PROVINCE", "longitude": "0.0", "PriceGroup": "", "CustomerName": "ABATAN PHARMACY"],
["Phone": "", "Contact": "", "SearchName": "ABC", "CreditLimit": "0.0", "latitude": "16.8043892", "ChineseName": "ABC", "CustNo": "2018002502", "Address": "BESAO. MT. PROVINCE", "AgentID": "GBIBAG VAN MT. PROVINCE", "longitude": "120.8209413", "PriceGroup": "", "CustomerName": "ABC"],
["Phone": "", "Contact": "", "SearchName": "ABENT", "CreditLimit": "0.0", "latitude": "0", "ChineseName": "ABENT", "CustNo": "2018002503", "Address": "COTCOT", "AgentID": "GBIBAG VAN MT. PROVINCE", "longitude": "0.0", "PriceGroup": "", "CustomerName": "ABENT"]]
var customerNumbers = [Int]()
for item in rtn.enumerated() {
let custNo = item.element["CustNo"] ?? ""
customerNumbers.append(Int(custNo)!)
}
print(customerNumbers)
@Chris_Parker what to do for all elements dynamically I need not to take custNo alone I need to each and every phone contact search name etc dynamically
What you need is a data model that has properties for each of the elements that you need. That can either be a class or a struct.
It’s early morning here so I will post you a sample of code after breakfast.
Have you started to learn SwiftUI or are you using UIKit (storyboard)?
Here is some Playground code that you should be able to adapt to suit your project.
struct CustomerRecord {
var phone: String
var contact: String
var searchName: String
var creditLimit: Double
var latitude: Double
var chineseName: String
var customerNumber: Int
var address: String
var agentId: String
var longitude: Double
var priceGroup: String
var customerName: String
}
let rtn = [
["Phone": "", "Contact": "", "SearchName": "2 JS - ABATAN", "CreditLimit": "0.0", "latitude": "0", "ChineseName": "2 JS - ABATAN", "CustNo": "2018002494", "Address": "LOO, ABATAN", "AgentID": "GBIBAG VAN MT. PROVINCE", "longitude": "0.0", "PriceGroup": "", "CustomerName": "2 J`S - ABATAN"],
["Phone": "", "Contact": "", "SearchName": "3J CALIKING", "CreditLimit": "0.0", "latitude": "16.80337503", "ChineseName": "3J CALIKING", "CustNo": "2018002495", "Address": "CALIKING", "AgentID": "GBIBAG VAN MT. PROVINCE", "longitude": "120.8216937", "PriceGroup": "", "CustomerName": "3J CALIKING"],
["Phone": "", "Contact": "", "SearchName": "4J", "CreditLimit": "0.0", "latitude": "0", "ChineseName": "4J", "CustNo": "2018002496", "Address": "BESAO. MT. PROVINCE", "AgentID": "GBIBAG VAN MT. PROVINCE", "longitude": "0.0", "PriceGroup": "0", "CustomerName": "4J"],
["Phone": "", "Contact": "", "SearchName": "7J", "CreditLimit": "0.0", "latitude": "0", "ChineseName": "7J", "CustNo": "2018002497", "Address": "SAGADA", "AgentID": "GBIBAG VAN MT. PROVINCE", "longitude": "0.0", "PriceGroup": "", "CustomerName": "7J"],
["Phone": "", "Contact": "", "SearchName": "7J", "CreditLimit": "0.0", "latitude": "0", "ChineseName": "7J", "CustNo": "2018002498", "Address": "SAGADA", "AgentID": "GBIBAG VAN MT. PROVINCE", "longitude": "0.0", "PriceGroup": "", "CustomerName": "7J"],
["Phone": "", "Contact": "", "SearchName": "97 BUY", "CreditLimit": "0.0", "latitude": "0", "ChineseName": "97 BUY", "CustNo": "2018002499", "Address": "SAGADA", "AgentID": "GBIBAG VAN MT. PROVINCE", "longitude": "0.0", "PriceGroup": "", "CustomerName": "97 BUY"],
["Phone": "", "Contact": "", "SearchName": "A & J", "CreditLimit": "0.0", "latitude": "0", "ChineseName": "A & J", "CustNo": "2018002500", "Address": "LOO, ABATAN", "AgentID": "GBIBAG VAN MT. PROVINCE", "longitude": "0.0", "PriceGroup": "0", "CustomerName": "A & J"],
["Phone": "", "Contact": "", "SearchName": "ABATAN PHARMACY", "CreditLimit": "0.0", "latitude": "0", "ChineseName": "ABATAN PHARMACY", "CustNo": "2018002501", "Address": "ABATAN", "AgentID": "GBIBAG VAN MT. PROVINCE", "longitude": "0.0", "PriceGroup": "", "CustomerName": "ABATAN PHARMACY"],
["Phone": "", "Contact": "", "SearchName": "ABC", "CreditLimit": "0.0", "latitude": "16.8043892", "ChineseName": "ABC", "CustNo": "2018002502", "Address": "BESAO. MT. PROVINCE", "AgentID": "GBIBAG VAN MT. PROVINCE", "longitude": "120.8209413", "PriceGroup": "", "CustomerName": "ABC"],
["Phone": "", "Contact": "", "SearchName": "ABENT", "CreditLimit": "0.0", "latitude": "0", "ChineseName": "ABENT", "CustNo": "2018002503", "Address": "COTCOT", "AgentID": "GBIBAG VAN MT. PROVINCE", "longitude": "0.0", "PriceGroup": "", "CustomerName": "ABENT"]]
var customers = [CustomerRecord]()
for item in rtn.enumerated() {
let newRecord = CustomerRecord(
phone: item.element["Phone"] ?? "",
contact: item.element["Contact"] ?? "",
searchName: item.element["SearchName"] ?? "",
creditLimit: Double(item.element["CreditLimit"] ?? "") ?? 0,
latitude: Double(item.element["latitude"] ?? "") ?? 0,
chineseName: item.element["ChineseName"] ?? "",
customerNumber: Int(item.element["CreditLimit"] ?? "") ?? 0,
address: item.element["Address"] ?? "",
agentId: item.element["AgentID"] ?? "",
longitude: Double(item.element["longitude"] ?? "") ?? 0,
priceGroup: item.element["PriceGroup"] ?? "",
customerName: item.element["CustomerName"] ?? "")
let custNo = item.element["CustNo"] ?? ""
customers.append(newRecord)
}
print(customers
Well done.