I have one nsmutable Array , How to add one keyvalue in nsmutable array at index number
This is array
(
{
id = 1;
name = "Tommy";
},
{
id = 2;
name = "Dad";
},
{
id = 3;
name = "Mom";
},
{
id = 4;
name = "Vic";
},
{
id = 5;
name = "Tom";
},
{
id = 6;
name = "Pam";
}
)
Now Index number 3 how to add "Class = 4th" and change name
{
id = 4;
name = "Nishant ";
class = "4th"
}
Please give ME solution
i am new in Swift.
Related
I have an iOS app in Swift integrated with a Neo4j database using Theo. I want to read the data from the database, so I'm executing a transaction like this:
let createStatement = "MATCH (n:`\(labelName)`) RETURN n"
let resultDataContents = ["row", "graph"]
let statement = ["statement" : createStatement, "resultDataContents" :
resultDataContents] as [String : Any]
let statements = [statement]
theo.executeTransaction(statements, completionBlock: {(response, error) in
print("response: \(response)")
})
This is executed correctly, and the "response" value is returned with the data, but I don't know how to extract the relationships and properties that I need from it. This is how the data is formatted whenever I print the "response" value:
["results": <__NSSingleObjectArrayI 0x60400000f630>(
{
columns = (
n
);
data = (
{
graph = {
nodes = (
{
id = 0;
labels = (
"Carl"
);
properties = {
image = "gs://nocan-4a3d8.appspot.com/DGHSA4057-D30B-4FC2-995A-E9GASD12FCFA/-LASDFASSIGiZ7cLQhRKaK5";
};
}
);
relationships = (
);
};
meta = (
{
deleted = 0;
id = 0;
type = node;
}
);
row = (
{
image = "gs://nocan-4a3d8.appspot.com/61DA4057-FSA0B-4FC2-995A-E9AF3TAFS2FCFA/-LDOIXIGiZ7cLQASDKaK5";
}
);
},
{
graph = {
nodes = (
{
id = 1;
labels = (
"Carl"
);
properties = {
note = Lgaksdlglksankgas;
};
}
);
relationships = (
);
};
meta = (
{
deleted = 0;
id = 1;
type = node;
}
);
row = (
{
note = Lgaksdlglksankgas;
}
);
},
{
graph = {
nodes = (
{
id = 20;
labels = (
"Carl"
);
properties = {
note = Lkwenglkagsd;
};
}
);
relationships = (
);
};
meta = (
{
deleted = 0;
id = 20;
type = node;
}
);
row = (
{
note = Lkwenglkagsd;
}
);
},
{
graph = {
nodes = (
{
id = 40;
labels = (
"Carl"
);
properties = {
image = "gs://nocan-4a3d8.appspot.com/5MAFSA4057-D30B-4FC2-995A-2DAKASD412FCFA/-LEOIXQ8MZ4lvOWvlka7";
};
}
);
relationships = (
);
};
meta = (
{
deleted = 0;
id = 40;
type = node;
}
);
row = (
{
image = "gs://nocan-4a3d8.appspot.com/DGA7A4057-830B-4FC2-995A-E9ADI3DA2FCFA/-WEFDOIX5SMZ4lvOWvlka7";
}
);
}
);
}
)
, "errors": <__NSArray0 0x600000005db0>(
)
]
What kind of object even is this? How do I extract the data and the values that I need? I am just lost. Any help or insight is greatly appreciated.
Say I have JSON like this:
["conferences": <__NSArrayI 0x60c00002f720>(
{
alias = Conference1;
divisions = (
{
alias = "Division 1";
id = "b95cd27d-d631-4fe1-bc05-0ae47fc0b14b";
name = "Division 1";
teams = (
{
alias = OXC;
id = "768c92aa-75ff-4a43-bcc0-f2798c2e1724";
market = East;
name = Rams;
references = (
{
id = Rams;
origin = gsis;
}
);
{
alias = AXC;
id = "768c92aa-75ff-4a43-bcc0-f2798c2e1724";
market = East;
name = Platypus;
references = (
{
id = Platypus;
origin = gsis;
}
);
},
{
alias = "Division 2";
id = "b95cd27d-d631-4fe1-bc05-0ae47fc0b14b";
name = "Division 2";
teams = (
{
alias = NXC;
id = "768c92aa-75ff-4a43-bcc0-f2798c2e1724";
market = West;
name = Ants;
references = (
{
id = Ants;
origin = gsis;
}
);
{
alias = QXC;
id = "768c92aa-75ff-4a43-bcc0-f2798c2e1724";
market = West;
name = Bulls;
references = (
{
id = Bulls;
origin = gsis;
}
);
},
}]
I'm at a lost as to how to create an object that contains the team data but also the Conference and Division alias.
I started down this path but this seems like it'll just basically dump all the json onto the object. I don't want that overhead obviously.
struct Team:Codable {
var arrConference:[Conference]
private enum CodingKeys: String, CodingKey {
case arrConference = "conferences"
}
struct Conference:Codable {
var conferenceName:String
var conferenceID:String
private enum CodingKeys: String, CodingKey {
case conferenceName = "alias"
case conferenceID = "id"
}
}
}
I guess I am stuck thinking in an old way, but how do you enumerate through the data with a codable?
I have some objects:
var array = [];
var obj1 = new Object();
obj1.category = 0;
obj1.sequence = 0;
obj1.otherAttr = 1;
array.push(obj1)
var obj2 = new Object();
obj2.category = 1;
obj2.sequence = 2;
obj1.otherAttr = 2;
array.push(obj2)
var obj3 = new Object();
obj3.category = 4;
obj4.sequence = 3;
obj1.otherAttr = 3;
array.push(obj3)
...
and I have collection in MongoDB:
{
category:0,
sequence:0,
anotherAttr:1
},
{
category:0,
sequence:1,
anotherAttr:2
},
{
category:0,
sequence:2,
anotherAttr:3
},
{
category:1,
sequence:0,
anotherAttr:4
},
{
category:1,
sequence:1,
anotherAttr:5
},
{
category:1,
sequence:2,
anotherAttr:6
},
...
I wanna insert these objects. But Before insert these, I want check overlapping category and sequence between these and document in MongoDB unrelated to otherAttr or anotherAttr. For example, I have objects like top, the result I need is :
{
category:0,
sequence:0,
anotherAttr:1
},
{
category:1,
sequence:1,
anotherAttr:5
}
I tried to $match. But can't check some conditions in many attributes.
After parsing a XML file the output is coming in following format in a dictionary
Now I want to convert it into array of dictionaries
Can anyone suggest a proper solution
Printing description of rootDictionary:
<CFBasicHash 0x8866000 [0x1078b38]>{type = mutable dict, count = 1,
entries =>
0 : <CFString 0x8869490 [0x1078b38]>{contents = "Data"} = <CFBasicHash 0x88695c0 [0x1078b38]>{type = mutable dict, count = 1,
entries =>
0 : <CFString 0x8869610 [0x1078b38]>{contents = "row"} = (
{
Address = {
text = "Skt. Clemens Torv 2-6";
};
City = {
text = "Aarhus C";
};
Country = {
text = Danmark;
};
Description = {
text = Ottopiste;
};
Lat = {
text = "56.156818";
};
Lon = {
text = "10.2092532";
};
Name = {
text = Ottopisteet;
};
Type = {
text = 1;
};
Zip = {
text = 8000;
};
},
{
Address = {
text = "Kauppatie 66";
};
City = {
text = Kauhava;
};
Country = {
text = Finland;
};
Description = {
text = "(null)";
};
Lat = {
text = "63.1001586";
};
Lon = {
text = "23.0463634";
};
Name = {
text = I m Here;
};
Type = {
text = 2;
};
Zip = {
text = 62200;
};
}
)
}
}
Now the output dictionary is in above format now again I want to convert it into array of dictionaries
Actual format of XML for reference:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Data>
<row>
<Lat>56.156818</Lat>
<Lon>10.2092532</Lon>
<City>Aarhus C</City>
<Address>Skt. Clemens Torv 2-6</Address>
<Zip>8000</Zip>
<Country>Danmark</Country>
<Name>Ottopisteet</Name>
<Description>Ottopiste</Description>
<Type>1</Type>
</row>
<row>
<Lat>63.1001586</Lat>
<Lon>23.0463634</Lon>
<City>Kauhava</City>
<Address>Kauppatie 66</Address>
<Zip>62200</Zip>
<Country>Finland</Country>
<Name>I am Here</Name>
<Description>(null)</Description>
<Type>2</Type>
</row>
</Data>
DO this:
NSMutableArray *arrData = [[parsedValueDictionary objectForKey:#"Data"] objectForKey:#"row"];
You could just iterate on the dictionary of rows and add each object to an array:
NSMutableArray *arrayOfDictionaries = [[NSMutableArray alloc] init];
NSDictionary *rows = [rootDictionary objectForKey:#"Data"];
[rows enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop){
[arrayOfDictionaries addObject:obj];
}];
UPDATE: I'm assuming that there are just "row" entries in the "Data" dictionary. Otherwise you should perform a check on the key to si if it's a "row" before.
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.