How to get key path for item in dictionary inside many arrays - nsarray

I have an array contains dictionary and the dictionary contain array so on so on.
How i can get the key path for item inside one of that arrays.
I need this to present hierarchy data (tree) in my database to outlineView, so , i can deal with the firs row in my array by using key path like (parent.children.parent) but the problem when (children) has many items and one of that items has more items ext. how can i look at the pointer to it?
for example:
_people = [[NSMutableArray alloc]init];
Person *person = [[Person alloc]initWithName:#"parent" age:36];
[person addChild:[[Person alloc] initWithName:#"child1" age:55]];
[person addChild:[[Person alloc] initWithName:#"child2" age:15]];
[person addChild:[[Person alloc] initWithName:#"child3" age:20]];
[(Person*)[person.childrens objectAtIndex:1] addChild:[[Person alloc] initWithName:#"child1 for child2" age:23]];
[(Person*)[[[person.childrens objectAtIndex:1] childrens] objectAtIndex:0]addChild:[[Person alloc] initWithName:#"last child" age:30]];
[_people addObject:person];
Now how i can locate to key for value "last child"
any help please!

Related

How to turn an AppleScript list into a string

Trying to learn how to use AppleScript records and lists to their upmost potential I've been trying to create a report of a BBEdit project but I'm finding very limited documentation. I asked a question yesterday trying to figure out why my find pattern wasn't working but after finding out that the issue was from me lacking returning results:true I was able to get the result record and I verified it was a record after reading Class and running:
class of findFunction
Since it says it's a record I reviewed here and ran length of findFunction and count of findFunction and they both returned 2. I was curious to know what the two items were in the record so I used return findFunction and was told there was:
found: true
found matches: list of X items
Wanting to know where and what files the matches were located in the list, I did some more searching and read Lists and records and ran:
set theMatches to get found matches of findFunction
it returned the list items and checking the new variable with get count of theMatches I am able get the quantity of items in the targeted list inside the record. When I review what's in the list (learned from: How to get a value from a list with a string in AppleScript? and Searching for items in list) I am able to conclude that when using the find in BBEdit every item in the list contains:
end_offset :
match_string :
message :
result_file :
result_kind :
result_line :
start_offset :
Experimenting with an item I set a variable with:
set itemOne to get item 1 of theMatches
and checked to see if it worked with:
display dialog (result_file of itemOne) as text
and a dialog with the full file path was displayed. Trying to utilize DRY I created:
set filesResult to get (result_file of (get item 1 of theMatches)) as text
Wanting to add any of the mentioned above to a file with something like:
set filesResult to get (result_file of (get item 1 of theMatches)) as text
set theMessage to get (message of (get item 1 of theMatches)) as text
set combined to filesResult & ":" & theMessage
I recalled being able to use the clipboard and found Set clipboard to Applescript variable? so I added:
set filesResult to the clipboard
make new text document
paste
but my issue I'm running into is how can I take every item in the list found_matches and add it to the clipboard an item on each line? I thought about using a repeat but I get an error when I try:
repeat with x from 1 to (length of matchesItems)
set filesResult to get (result_file of (get item x of theMatches)) as text
set theMessage to get (message of (get item x of theMatches)) as text
set combined to filesResult & ":" & theMessage
end repeat
With a message of:
The variable matchesItems is not defined.
So how can I get every item from the list into the clipboard with every item on it's own line so I can paste all items from the clipboard into a new file?
To clarify wording
theList = {A,B,C} -- this is a list with 3 variables
theRecord = {A:something, B:somethingElse, C:somethingElseTwo} -- this is a record.
A list can be addressed by its index.
theList's item 1 -- A
A record can be addressed by its keys
A of theRecord -- something
To get all items of a list into a string repeat it by its index (saying every item is of type text)
set finalString to ""
repeat with thisItem in TheList
set finalString to finalString & thisItem & return -- the return creates a new line
end repeat
Then you have finalString to do with whatever you like.
To get every item of a record you have to know it's keys (if it's not a ASOC NSDictionary)
set finalString to ""
set finalString to finalString & A of theRecord & return;
-- repeat last line with every key

Android List View with multiple items displaying them horizontally

I have a list view in my activity and it is getting some items from database like Name,Played Games,Games won.
Now i'm displaying these items in a list view
I want to design like this
Name Games Played Games won
XXX 5 3
But after running the application it looks like this
Name Games Played Games won
XXX
5
3
XXX
8
5
So i want to display these three values in a same list item horizontally,Please help me
List<String> score = new ArrayList<String>();
db=this.openOrCreateDatabase("Hangman",MODE_PRIVATE, null);
c=db.rawQuery("Select name,gamesplayed,gameswon from users",null);
if(c.moveToFirst()){
do{
String usr=c.getString(c.getColumnIndex("name"));
String played=c.getString(c.getColumnIndex("gamesplayed"));
String won=c.getString(c.getColumnIndex("gameswon"));
score.add(usr);
score.add(played);
score.add(won);
}while(c.moveToNext());
}
ArrayAdapter<String> adptr= new ArrayAdapter<String>(this,R.layout.row,R.id.member_name,score);
lv1.setAdapter(adptr);
}
If you want to display them horizontally then you just make a cocatenated string and add it only once
String val=usr + "" + played +........;
score.add(val);
You need a custom list view adapter, http://www.vogella.com/tutorials/AndroidListView/article.html#adapterown provides a good tutorial

How to remove element from List<string[]> and put it at the end of the list?

I have a
List<string[]> list which contains this data:
SEC Code (list[0][0])
Status (list[0][1])
ALL (list[1][0])
None (list[1][1])
The data is like this:
SEC Code ALL
Status None
I want to remove "SEC Code" and "ALL" and put them at the end of the list. I tried list.Remove, but it works for
List<string> and not for List<string[]>.
I tried list.Remove, but it works for List<string> and not for List<string[]>.
This is because list.Remove compares items for equality using the Equals(object) which arrays do not override. In order for an array to be considered equal to another array from the Equals(object)'s point of view, it must be the same array instance.
In order to remove "SEC Code" and "ALL" from an inner array you need to build a new array that is shorter by one item, like this:
var toRemove = new HashSet<string> {"SEC Code", "ALL"};
var newList = list.Select(array =>
array.Where(item => !toRemove.Contains(item)).ToArray()
).ToList();
The code above produces a list of string arrays from which all "SEC Code" and "ALL" strings have been removed.

How to access the list of items in a combobox

What is the "object type" of the .List property of a combobox in vba? I am having quite a struggle in accessing the items when I treat it like a an Array of strings.
Let's say I want to go through the list and check if any of the items match a certain string, how would I go about that?
Levraininjaneer, I think I might have some help for you...
I've made a windows form with a combobox, a button, and a listbox... The combobox has some items in it, like Item 1 to Item 3, "ABC", "DEF", "GHI"...
Now, you say you want to access the items in your list? Well, try this out...
string[] array = new string[comboBox1.Items.Count];
int itemCount = comboBox1.Items.Count;
for (int i = 0; i < itemCount; i++)
{
array[i] = (string)comboBox1.Items[i];
string item = array[i].ToString();
this.listBox1.Items.Add(item);
}
MessageBox.Show(array[1]);
MessageBox.Show(array[4]);
And it will do this:
And the message boxes at the bottom of the code will display "Item 2" & "DEF"
If you want to "save" an instance of an item in the list box, you can also do it like this:
string arrayItem = array[3].ToString();
MessageBox.Show(arrayItem);
This will display a message box saying "ABC" as the index (number in [square] brackets, it starts at 0 generally... So if you put array [1] . it's not the 1st item, it's actually the 2nd item... If you wanted to get the last item, and if there's 6 items, it would be:
array[5];
And also, if you wanted to check if an object contains a certain string, you can always use the .Contains method of a string
.Contains("Item")
Hope this helps :)
Win10Pro(x64)
Visual Studio 2015 Community
C#
WindowsForm project

list(t) always returns the last item (class) entered

I am trying to to use list(of someclass) to keep track of an array of simular data for use at a later time in the program by using the .add() property. When I do I always get back the last item entered.
Dim lst as new list(of superclass)
Dim work as new list(of superclass)
Program execution to fill work before storage.
Lst.add(work)
Then list the list
For each wrk in lst
Print(lst)
Next
Try printing wrk instead of lst.