Pass Complex parameters by POST in alamofire - swift

let newTodo = [
"currentPageNo" : (page.description) ,
"type": "basic_search",
"searchParams": [
"remember_search" : checkk ,
"u_seeking": (bsMatch_looking) ,
"age_from" : (bsMatch_agefrom) ,
"age_to": (bsMatch_ageto),
"u_looking_for_value" :(bsMatch_lookingfoevalue),
"u_country": (bsMatch_country) ,
"u_state" : (bsMatch_ustate) ,
"u_city": (bsMatch_city) ,
"u_postalcode" : (bsMatch_postelcode) ,
"distance": (bsMatch_distance) ,
]
] as [String : AnyObject]
response is below
["type": basic_search , "currentPageNo": 1 ,"searchParams": {
"age_from" = 18;
"age_to" = 44;
distance = 0;
"remember_search" = On;
"u_city" = "";
"u_country" = 1;
"u_looking_for_value" = 0;
"u_postalcode" = "";
"u_seeking" = Female;
"u_state" = California;
}]
But I want this type of response how can I do this only brasses makes the problem for me please provide me the solution
[{ "currentPageNo": 1, "type": basic_search ,"searchParams": {
"age_from" = 20;
"age_to" = 35;
distance = 100;
"remember_search" = On;
"u_city" = London;
"u_country" = 222;
"u_looking_for_value" = "0";
"u_postalcode" = "";
"u_seeking" = Male;
"u_state" = England;
}}]
I want to convert the first code into the second type

You can order them by having keys with type Int.
var myDictionary: [Int: [String: String]]?

Related

Swift Firebase RealtimeDatabase doesn't give child specific data with tons of data

In my project I used to have more than 6.000 points of interest (pois). Now I need to access for example the title of one poi with specific ID. Normally it works fine in my app when I need some specific from user for example.
I do the same steps like I usually do. But when I try to access poi data, it only give the whole "poi" data (>6.000 pois). I tried getData even observeSingeEvent.
This is my database structure:
{
"pois" : {
"0015CF32-D5B2-481A-8DA2-877E621A4E82" : {
city = a,
"country" = a,
creator = System,
id = "0015CF32-D5B2-481A-8DA2-877E621A4E82",
latitude = "1",
longitude = "1",
street = "a",
title = "a",
type = 0,
zip = 1
}, + 6.000 more...
"users" : {
"6EA555FA-BAA8-4EDE-BD05-5D290B953CAC" : {
"City" : "Motown",
"Country" : "Anywhere",
"Forename" : "Fred",
"Surename" : "Feuerstein",
"onTour" : "false",
"registeredEmail" : "fred#feuerstein.com",
"userId" : "6EA555FA-BAA8-4EDE-BD05-5D290B953CAC",
"userImagePath" : "6EA555FA-BAA8-4EDE-BD05-5D290B953CAC.jpg",
"username" : "Tom"
}
}
}
My request and result for user data: (I reduced the whole code because it doesn't matter what happens within the completion)
database.child("users/6EA555FA-BAA8-4EDE-BD05-5D290B953CAC/registeredEmail").getData { error, snap in
print(snap)
}
results: Snap (registeredEmail) fred#feuerstein.com
My request and result for user data.
database.child("pois/42E11715-B3B0-46D9-A568-E578870EF9A4/title/").getData { error, snap in
print(snap)
}
results (Shorten):
Snap (title) {
"0015CF32-D5B2-481A-8DA2-877E621A4E82" = {
city = a;
"country" = a;
creator = System;
id = "0015CF32-D5B2-481A-8DA2-877E621A4E82";
latitude = "1";
longitude = "1";
street = "a";
title = "a";
type = 0;
zip = 1;
};
"002A3A1C-DE5C-4CB4-AD36-1B4495B77F22" = {
city = "b";
"country" = b;
creator = System;
id = "002A3A1C-DE5C-4CB4-AD36-1B4495B77F22";
latitude = "1";
longitude = "1";
rating = 0;
street = "b";
title = "b";
type = 0;
zip = 1;
}; + 6.000 more pois
I guess this coherent with the amount of data in "pois". Someone an idea how to solve the problem?

Remove All Items from NSDictionary/Dictionary where value == -1.0

I am migrating my data from 1 format to another for a large update to one of my iOS apps. This means that when a user updates their application it migrates their data to a new location. This new location has much stricter rules and uses proper practices (basically when I first created the app I was a noob and there are bad practices currently in the database and this new location is for good data only).
I have everything migrating nicely and everything works except I need to do one last thing. The large dictionary that I save to the database (it uses firebase fyi) has -1.0 stored everywhere there should be a nil value (bad, I know). What I need to do is loop through the entire dictionary and remove any key where the value of that key is -1.0.
The Dictionary is of type [AnyHashable : Any] which is what firebase uses.
I have tried this so far.
if let data = dataDictionary as? [AnyHashable : Any] {
let foundItems = data.filter { $0.value as? Double == -1.0 }
print(foundItems)
}
the plan was to then loop through that found items array and remove any key from the data dictionary that contained it.
This is what the data dictionary looks like:
"-KpIdh_TQMG4fyfFgkdt" = {
assignments = {
"-KpIgH6uN19OpcuedYe1" = {
assignmentGoal = "-1";
assignmentName = "Information System Proposal";
assignmentResult = 100;
assignmentWeight = 5;
};
"-KpIgJnFlC6fhgS0NWxF" = {
assignmentGoal = "-1";
assignmentName = "Information System";
assignmentResult = "-1";
assignmentWeight = 35;
};
"-KpIgOGSAwg_VSpDWhWR" = {
assignmentGoal = "-1";
assignmentName = "Process Analysis";
assignmentResult = "-1";
assignmentWeight = 30;
};
"-KpIgPhu_3Zxw36xt3O4" = {
assignmentGoal = "-1";
assignmentName = Labs;
assignmentResult = "-1";
assignmentWeight = 10;
};
"-KpIgQoFEdRnLlMAq2VN" = {
assignmentGoal = "-1";
assignmentName = Exam;
assignmentResult = "-1";
assignmentWeight = 20;
};
};
paperColor = 22;
paperGoal = 95;
paperName = "Systems Analysis";
};
};
semesterCode = 17S2;
semesterGoal = 90;
semesterName = "2017 Semester Two";
};
};
and this is what it should look like
"-KpIdh_TQMG4fyfFgkdt" = {
assignments = {
"-KpIgH6uN19OpcuedYe1" = {
assignmentName = "Information System Proposal";
assignmentResult = 100;
assignmentWeight = 5;
};
"-KpIgJnFlC6fhgS0NWxF" = {
assignmentName = "Information System";
assignmentWeight = 35;
};
"-KpIgOGSAwg_VSpDWhWR" = {
assignmentName = "Process Analysis";
assignmentWeight = 30;
};
"-KpIgPhu_3Zxw36xt3O4" = {
assignmentName = Labs;
assignmentWeight = 10;
};
"-KpIgQoFEdRnLlMAq2VN" = {
assignmentName = Exam;
assignmentWeight = 20;
};
};
paperColor = 22;
paperGoal = 95;
paperName = "Systems Analysis";
};
};
semesterCode = 17S2;
semesterGoal = 90;
semesterName = "2017 Semester Two";
};
};
The solution I have is to map (iterate) over each parent key and assign it's child nodes to a variable child. Then test each child property (assignmentGoal, assignmentName etc) for either "-1" for the string and -1 for the ints. If it's a match, remove that key: value pair from child.
Then assign child back to the parent node.
let result: [Any] = dict.map { dictionary in
var d = dictionary
var child = d.value as Dictionary
if let goal = child["assignmentGoal"] as? String, goal == "-1" {
child.removeValue(forKey: "assignmentGoal")
}
if let name = child["assignmentName"] as? String, name == "-1" {
child.removeValue(forKey: "assignmentName")
}
if let result = child["assignmentResult"] as? Int, result == -1 {
child.removeValue(forKey: "assignmentResult")
}
if let weight = child["assignmentWeight"] as? Int, weight == -1 {
child.removeValue(forKey: "assignmentWeight")
}
d.value = child
return d
}
//show the output
for item in result {
print(item)
}
and the result output
(key: "-KpIgOGSAwg_VSpDWhWR",
value: ["assignmentName": "Process Analysis System", "assignmentWeight": 30])
(key: "-KpIgQoFEdRnLlMAq2VN",
value: ["assignmentName": "Exam", "assignmentWeight": 20])
(key: "-KpIgJnFlC6fhgS0NWxF",
value: ["assignmentName": "Information System", "assignmentGoal": "3", "assignmentWeight": 35])
(key: "-KpIgPhu_3Zxw36xt3O4",
value: ["assignmentName": "Labs", "assignmentWeight": 10])
(key: "-KpIgH6uN19OpcuedYe1",
value: ["assignmentName": "Information System Proposal", "assignmentResult": 100, "assignmentWeight": 5])

Swift accessing key from dictionary returning null

I have a dictionary. When I try to access that dictionary, it is returning a null value when it should definately be returning an actual value. I'm stumped. Any help is always appreciated.
if let d = response.result.value {
print(d) //prints correct data
let prices = d["prices"] as? [[String:AnyObject?]]
print(prices) //prints nil
let best_price = prices?[0]
let price = best_price?["price"] as? String
print(price) //prints nil
}
Console:
{
item = {
"item_number" = 57;
image = "http://example.com/tent.jpg";
name = "Small Red Tent";
};
prices = (
{
link = "http://example.com/id=19";
price = "58.15";
rating = "3.64";
"vendor_id" = 50;
},
{
link = "http://example.com/id=50";
price = "58.14";
rating = "5.00";
"vendor_id" = 110;
},
{
link = "http://example.com/id=26";
price = "50.40";
rating = "4.71";
"vendor_id" = 73;
},
{
link = "http://example.com/id=12";
price = "47.16";
rating = "4.00";
"vendor_id" = 1;
},
{
link = "http://example.com/id=13";
price = "45.75";
rating = "3.90";
"vendor_id" = 25;
},
{
link = "http://example.com/id=16";
price = "41.32";
rating = "3.02";
"vendor_id" = 16;
},
{
link = "http://example.com/id=1";
price = "36.59";
rating = "4.84";
"vendor_id" = 51;
},
{
link = "http://example.com/id=2";
price = "36.29";
rating = "3.26";
"vendor_id" = 43;
},
{
link = "http://example.com/id=13";
price = "34.59";
rating = "4.14";
"vendor_id" = 48;
},
{
link = "http://example.com/id=3";
price = "32.00";
rating = "4.29";
"vendor_id" = 53;
},
{
link = "http://example.com/id=4";
price = "24.50";
rating = "4.16";
"vendor_id" = 8;
},
{
link = "http://example.com/id=5";
price = "15.00";
rating = "4.87";
"vendor_id" = 39;
},
{
link = "http://example.com/id=6";
price = "0.00";
rating = "3.00";
"vendor_id" = 65;
}
);
}
nil
nil
So the solution was proposed by Larme solved the problem.
let prices = d["prices"] as? [AnyObject]
Although I never figured out why casting d["prices"] as? [[String:AnyObject?]] wouldn't also work.

NSJSONSerialization with google API

When I'm getting request from google maps API i use this method to get json:
NSDictionary *jsonArray = [NSJSONSerialization JSONObjectWithData:dataRequest options: NSJSONReadingAllowFragments error: nil];
jsons look's like this one:
{
routes = (
{
bounds = {
northeast = {
lat = "50.90961";
lng = "20.6492";
};
southwest = {
lat = "50.05775000000001";
lng = "19.94544";
};
};
copyrights = "Dane do Mapy \U00a92012 Google";
legs = (
{
distance = {
text = "126 km";
value = 126118;
};
duration = {
text = "2 godz. 0 min";
value = 7229;
};
"end_address" = "Aleja Powstania Warszawskiego 15, 30-001 Krak\U00f3w, Polska";
"end_location" = {
lat = "50.06";
lng = "19.9589";
};
"start_address" = "Mas\U0142owska 2, 25-001 Kielce, Polska";
"start_location" = {
lat = "50.88884";
lng = "20.6492";
};
steps = (
{
distance = {
text = "0,1 km";
value = 109;
};
duration = {
text = "1 min";
value = 39;
};
"end_location" = {
lat = "50.88824";
lng = "20.64796";
};
"html_instructions" = "Kieruj si\U0119 <b>Mas\U0142owska</b> na <b>po\U0142udniowy zach\U00f3d</b> w stron\U0119 <b>Szyd\U0142\U00f3wek G\U00f3rny</b>";
polyline = {
points = "gfruHo``}BvBvF";
};
"start_location" = {
lat = "50.88884";
lng = "20.6492";
};
"travel_mode" = DRIVING;
},
{
distance = {
text = "0,2 km";
value = 221;
};
duration = {
text = "2 min";
value = 97;
};
"end_location" = {
lat = "50.88896";
lng = "20.64503";
};
"html_instructions" = "Skr\U0119\U0107 <b>w prawo</b> w <b>Szyd\U0142\U00f3wek G\U00f3rny</b>";
polyline = {
points = "obruHwx_}BaCpOMv#";
};
"start_location" = {
lat = "50.88824";
lng = "20.64796";
};
"travel_mode" = DRIVING;
},
{
distance = {
text = "0,6 km";
value = 596;
};
duration = {
text = "1 min";
value = 56;
};
"end_location" = {
lat = "50.88427";
lng = "20.64091";
};
"html_instructions" = "Skr\U0119\U0107 <b>w lewo</b> w <b>Warszawska</b>";
polyline = {
points = "_gruHmf_}BrGvFjQ`OhA|#";
};
"start_location" = {
lat = "50.88896";
lng = "20.64503";
};
"travel_mode" = DRIVING;
},
{
distance = {
text = "1,0 km";
value = 950;
};
duration = {
text = "2 min";
value = 104;
};
"end_location" = {
lat = "50.88779";
lng = "20.62863";
};
"html_instructions" = "Skr\U0119\U0107 w drug\U0105 <b>w prawo</b> w kierunku <b>Jesionowa</b>";
polyline = {
points = "uiquHul~|BiEvScCzKs#xCmBhK_#dD}#dIk#tBYr#Mf#Op#MnA";
};
"start_location" = {
lat = "50.88427";
lng = "20.64091";
};
"travel_mode" = DRIVING;
},
{
distance = {
text = "4,2 km";
value = 4185;
};
duration = {
text = "5 min";
value = 292;
};
"end_location" = {
lat = "50.90806000000001";
lng = "20.58021";
};
"html_instructions" = "Na rondzie zjazd nr <b>1</b> w <b>\U0141\U00f3dzka</b>";
polyline = {
points = "u_ruH}_||BCd#Cf#?N#RDPHJJHsBzQIl#OrAm#bEEV[vBa#fBUfA_A~Bk#jA}DvGyDpEu#fAsA`C_AhBeAlCmAhDgAnDuAvEwAzFyAvGgA|F]bDH`Ba#fCQjA]tBi#hC}#zDsB|GeBdDwD|Gg#~#cAhBGJ_H`Mo#jAiB`DaAlBcBfD_#`A[fACDuCrMcC`L?#{AhHw#rDiDhPSx#e#dBc#vAa#fAi#jAgCfF{#rAe#p#A#m#p#kBhB";
};
"start_location" = {
lat = "50.88779";
lng = "20.62863";
};
"travel_mode" = DRIVING;
},
{
distance = {
text = "0,2 km";
value = 213;
};
duration = {
text = "1 min";
value = 54;
};
"end_location" = {
lat = "50.90968";
lng = "20.57859";
};
"html_instructions" = "Kontynuuj wzd\U0142u\U017c <b>Trasa 74</b>";
polyline = {
points = "k~uuHiqr|BkBzAiEtEMP";
};
"start_location" = {
lat = "50.90806000000001";
lng = "20.58021";
};
"travel_mode" = DRIVING;
},
{
distance = {
text = "92,8 km";
value = 92776;
};
duration = {
text = "1 godz. 17 min";
value = 4641;
};
"end_location" = {
lat = "50.24777";
lng = "20.08501";
};
"html_instructions" = "Skr\U0119\U0107 <b>w lewo</b> w <b>E77</b>";
......
status = OK;
}
Next i use this method to get value for "points" key:
NSArray *items = [jsonArray valueForKeyPath:#"routes.legs.steps.polyline.points"];
When i want to print arrays elements it give only one element (it's strange because i have 25 points in json), and result looks like this one:
(
(
"gfruHo``}BvBvF",
"obruHwx_}BaCpOMv#",
"_gruHmf_}BrGvFjQ`OhA|#",
"uiquHul~|BiEvScCzKs#xCmBhK_#dD}#dIk#tBYr#Mf#Op#MnA",
"u_ruH}_||BCd#Cf#?N#RDPHJJHsBzQIl#OrAm#bEEV[vBa#fBUfA_A~Bk#jA}DvGyDpEu#fAsA`C_AhBeAlCmAhDgAnDuAvEwAzFyAvGgA|F]bDH`Ba#fCQjA]tBi#hC}#zDsB|GeBdDwD|Gg#~#cAhBGJ_H`Mo#jAiB`DaAlBcBfD_#`A[fACDuCrMcC`L?#{AhHw#rDiDhPSx#e#dBc#vAa#fAi#jAgCfF{#rAe#p#A#m#p#kBhB",
"k~uuHiqr|BkBzAiEtEMP",
"ohvuHegr|Bl#rCN`#Xf#n#h#xAx#hAz#nAdCtFdf#~Dv]~Ipu#zHpq#hAjIpA`JhBbJ`CxJj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ZxBn#`IfBlAb#fAv#",
"k~opHceyxBd#j#TTPt#FT",
"u{opHu`yxBoBTu#BuHl#o#BI#",
"klppHg~xxBMqFxAI"
)
)
How can i get a normal NSArray with 25 NSString object?
You're looking at the correct output from the polyline field in the JSON. The data is encoded with Google's polyline encoding, which is documented here
https://developers.google.com/maps/documentation/utilities/polylinealgorithm
There are a number of methods online for parsing said string in objective-c, such as this one.
Ok, i have found the solution parsing json with NSJSONSerialization:
NSDictionary *jsonArray = [NSJSONSerialization JSONObjectWithData:dataRequest options:NSJSONReadingMutableContainers error: nil];
NSArray * items = [jsonArray valueForKeyPath:#"routes.legs.steps.polyline.points"];
items = [items objectAtIndex:0];
items = [items objectAtIndex:0];
And in items array you will get string with encode direction

objectAtIndex in NSDictionary

I am trying to create UITableView from my NSDictionary, but how can I use objectForKey? Convert to NSArray?
I need help.
My dictionary looks like:
**
{
"allow_comments" = 1;
category = 1024194;
"created_at" = "2011-11-17T01:44";
forum = 1005401;
"forum_obj" = {
"created_at" = "2011-09-03 03:04:43.514514";
description = "";
id = 1005401;
name = smartfiction;
shortname = smartfiction;
};
hidden = 0;
id = 474530565;
identifier = (
"2507 http://smartfiction.ru/?p=2507"
);
"num_comments" = 2;
slug = "thread_9714";
title = "\U041e\U0440\U0438\U0444\U043b\U0430\U043c\U043c\U0430. \U042d\U0436\U0435\U043d \U0418\U043e\U043d\U0435\U0441\U043a\U043e";
url = "http://smartfiction.ru/prose/oriflamma/";
}
2011-11-19 10:21:25.992 ARSSReader[3067:15503] id 474530565
2011-11-19 10:21:26.864 ARSSReader[3067:15503] Ответ #2: (
{
author = {
avatar = {
cache = "http://www.gravatar.com/avatar.php?gravatar_id=af6c6f08e213427ad611b00589db00f9&size=32&default=http://mediacdn.disqus.com/1321567697/images/noavatar32.png";
permalink = "http://www.gravatar.com/avatar.php?gravatar_id=af6c6f08e213427ad611b00589db00f9&size=32&default=http://mediacdn.disqus.com/1321567697/images/noavatar32.png";
};
emailHash = af6c6f08e213427ad611b00589db00f9;
isAnonymous = 1;
name = "S Shv";
profileUrl = "http://disqus.com/guest/af6c6f08e213427ad611b00589db00f9/";
url = "";
};
createdAt = "2011-11-17T22:39:36";
dislikes = 0;
forum = smartfiction;
id = 367003621;
isApproved = 1;
isDeleted = 0;
isEdited = 0;
isFlagged = 0;
isHighlighted = 0;
isJuliaFlagged = 1;
isSpam = 0;
likes = 0;
media = (
);
message = "\U043f\U043e\U0440\U0430\U0437\U0438\U043b\U043e )";
parent = "<null>";
points = 0;
"raw_message" = "\U043f\U043e\U0440\U0430\U0437\U0438\U043b\U043e )";
thread = 474530565;
},
{
author = {
avatar = {
cache = "http://www.gravatar.com/avatar.php?gravatar_id=c1c53088e04a60aab74cd1f149117e69&size=32&default=http://mediacdn.disqus.com/1321567697/images/noavatar32.png";
permalink = "http://www.gravatar.com/avatar.php?gravatar_id=c1c53088e04a60aab74cd1f149117e69&size=32&default=http://mediacdn.disqus.com/1321567697/images/noavatar32.png";
};
emailHash = c1c53088e04a60aab74cd1f149117e69;
isAnonymous = 1;
name = "3,14";
profileUrl = "http://disqus.com/guest/c1c53088e04a60aab74cd1f149117e69/";
url = "";
};
createdAt = "2011-11-17T02:52:46";
dislikes = 0;
forum = smartfiction;
id = 365544459;
isApproved = 1;
isDeleted = 0;
isEdited = 0;
isFlagged = 0;
isHighlighted = 0;
isJuliaFlagged = 1;
isSpam = 0;
likes = 1;
media = (
);
message = "\U0427\U0438\U0442\U0430\U0442\U044c \U043d\U0430 \U043d\U043e\U0447\U044c \U043f\U0440\U043e\U043a\U0440\U0430\U0441\U0442\U0438\U043d\U0430\U0442\U043e\U0440\U0430\U043c. \U0412\U043f\U0440\U043e\U0447\U0435\U043c, \U043b\U0443\U0447\U0448\U0435 \U0443\U0442\U0440\U043e\U043c.";
parent = "<null>";
points = 1;
"raw_message" = "\U0427\U0438\U0442\U0430\U0442\U044c \U043d\U0430 \U043d\U043e\U0447\U044c \U043f\U0440\U043e\U043a\U0440\U0430\U0441\U0442\U0438\U043d\U0430\U0442\U043e\U0440\U0430\U043c. \U0412\U043f\U0440\U043e\U0447\U0435\U043c, \U043b\U0443\U0447\U0448\U0435 \U0443\U0442\U0440\U043e\U043c.";
thread = 474530565;
}
)
**
It is comments from disqus.com. I want to create dictionaries for all comments and use them to create UITableView cells.
Instead of storing the comments from disqus.com in a dictionary, store each comment in an entry inside an array (it looks like each comment has a block of text you can encapsulate into an object which you can store into an array).
Dictionaries are good for associating values with keys.
Arrays are great for storing lists of objects, much like a list of comments from a disqus site.