Xcode - Objective C- How to make a dictionary of persons? - objective-c

I can't get my head around my objective C code. I want to make a dictionary with persons that I save in the app. The dictionary is in first empty and then we need to add it from the textfields I created (see image)textfieldWelkom
For every person that is added, we have to show it in a list (see image) lijstTabblad in the tableviewcontroller. (The list has to be the whole name of the person)
I don't get the idea of how to making a dictionary with multiple persons with every person his own ELEMENTS. And how that I can get the elements again out of de dictionary for making the list etc..
(not like the 1 example but multiple values with that person)
I would be sow thankfull if you could help me!
Greetings,
Kevin

You needs to first create single person dictionary dictionary keys
are like name sirname age and put values for respected keys
add this dictionary in one array or another dictionary(array/dictionary must be mutable array)

Related

Kotlin functional programming keep reference of previous object in List

I have a list of Person objects which are related to each other with spouse relation in the order of which they appear in the list.
enum class Gender {
MAN, WOMAN
}
data class Person(val name: String, val age: Int, val gender: Gender)
In the list, each Person with Gender MAN is the spouse of the following Person with WOMAN Gender (and vice versa) and each entry in the list is followed by alternating genders with MAN gender be the first.
The list should ideally be like [MAN, WOMAN, MAN, WOMAN, MAN, WOMAN] (obviously it will be a list of Person objects for simplicity I am putting a list of Gender here) but it could also be like [WOMAN, MAN, WOMAN, MAN, WOMAN, MAN]. In the latter case, the first appearing WOMAN is the spouse of the last appearing MAN.
How this second case could be handled in kotlin by using functional programming.
My current approach involves checking if the first Person has a gender women then i remove the first and last objects in the list and then add them in the end but this is not fully a functional programming solution.
Anyone can guide me about that?
Thanks
What do you mean by fully functional approach?
Similar to what you mentioned, you can fix the order by a simple statement like this:
val correctList = if(list.first().gender == MAN) list else list.drop(1) + list.first()
If you want a more general approach, you can do something like this:
// separate the people into a list of gender=MAN and a list of everyone else
// the result is a Pair, so I'm destructuring that into two variables
val (men, women) = people.partition { it.gender == MAN }
// use zip to take a person from each list and combine them into a list of pairs
men.zip(women)
// use flatMap to turn each pair into a list of two people
// just using map would create a list of lists, flatMap flattens that into
// a single list of people, alternating gender=MAN, gender=WOMAN
.flatMap { it.toList() }
This way it doesn't matter how your original list is ordered, it can start with any element and you can have the different types completely mixed up - BABBAABA will still come out as ABABABAB. So it's a general way to combine mixed data streams - partition separates them into groups, and zip lets you take an element from each group and do something with them.
Here I'm just letting zip create Pairs, and then flatMap turns those back into an ordered list (if that's what you want). You could also do a forEach on each pair instead (say if you wanted to set a value on each Person to link them to each other), or zip can take a transform function too.
Also zip terminates when one of the lists runs out (e.g for AAA and BB you'll get two pairs) so this works for generating complete pairs of elements - if you also needed to handle elements without a "partner" you'd need to do a bit more work

Objective C - Attribute values into Variables

I'm new to objective-C, having a programming background mainly in C++, and believe this to be an easy question although I can't find the answer to what I'm looking for. I'm using Xcode 6 as of now.
I have an entity "Song" in which I have various attributes, "Description", "Tempo", etc. My tempo attribute, for example, is limited to integers, and I want to be able to manipulate any/all of those tempo values for each Song at a given time. Upon a dedicated button click, I want to either edit the values or put all of the values in an array (array[0] = Song 1 Tempo, array[1] = Song 2 Tempo, etc), so mainly I need to get those individual values into variables, or so I think.
I feel as though my limited knowledge of attributes and entities is preventing me from being able to connect the bridge between them and variables, the latter of which I'm used to working with in C++, of course. Any suggestions or tips would be much appreciated, thanks in advance!
Pat
Your attribute will return collection type object like dictionary or array. So you can iterate your attributes values and just add in NSMutableArray.

Populate an Array in VB

I am writing a program for class that needs to ask the user for 3 different test scores from 3 different people and store that in an array. I am having issues with populating the array from the user input.
It should ask the user to enter in 3 scores for person 1, person 2, and person 3. Then Store it in a "three-element array of structure variables; each element will contain the test scores for one student"(to quote exactly what the book said).
Everything else I can do so any suggestions on how to tackle this would help me greatly.
There are many tutorials on Array
http://msdn.microsoft.com/en-us/library/wak0wfyt.aspx
http://www.tutorialspoint.com/vb.net/vb.net_arrays.htm
Creating an Array
Dim scores(2) As Double 'this creates an array with 3 elements
Populating it
scores.SetValue(99.5, 0) 'SetValue(the score fetched from input box, index number)
...and so on
Good luck.

How to avoid multiple Iterations to search and assign one of the possible object property to a variable ?

How can we avoid multiple iteration to search for an object's property and if found then assign it to a variable else search for another key ?
eq we have Video Class with one of the field as videoType which can have values as hq(high-quality),normal(normal), def(default)..etc and so on.
From an array containing multiple video objects, how can we search and return a particular object in an order that if the array contains object with property hq then first return it,else search for normal and proceed so on. if a set of n keys are to be tested in the key set (hq,normal,def,....) then do we always need to iterate the entire array "n" times unless the key is found.
Can this be done is single iteration ? Do we need to first sort the original array in the order of occurrence of the keys in desired key set. I hope my problem statement is clear.
One possible solution for this would be to create separate NSMutableArrays for each videoType. Then, as you iterate once over your array of video objects, you check its array type and add the video to the correct array.
After you finished iterating, you create the final mutable array by concatenating the other array with addObjectsFromArray.
If you have a lot or variable list of video types, you can create the separate mutable arrays as values in an NSDictionary, where the keys are the video types. This way, you can get the target array with one step, by fetching it from the dictionary.

Show more than one Object in a NSTableView row

I'm new here at stackoverflow :) But I think, this is the right place to ask my question.
I'm a new developer with Cocoa and Objective-c & I'm trying to write my first App for Mac: a ToDo App.
At this moment, i can save ToDo's and delete them, but now, I want to add some features like CreationDate, some Tags (in mutablearray), and if the ToDo is finished or not. Im not working with an ArrayController, I'm saving the encoded NSMutableArray into a File (Library/Application Support/AppName) and reading it from there.
This all must be in one Row, because it is looking Like this:
Current appearance http://img683.imageshack.us/img683/7595/bild2ss.png
Where Title is, should be the Content of the ToDo, where the Blue Box is, should be the Status (Blue = undone, Grey = Done) and where Subtitle is should be the Date and the Tags (03.01.2009 - tag1, tag2, tag3)
I now how to addObjects into an mutablearray but, if i wanna save all this 4 informations into this array, i dont know how to make this.
I've got an Model, which is initializing with this 4 infomations, but how to save this? Must I save this for informations in one array and this array in my mutablearray?
The solution is actually the opposite: Have one object per row.
This is where your model layer (the M in MVC) comes in: The object for each row is a model object, an instance of a class you construct, and the icon, title, and subtitle are properties of that object.
Then, make a custom cell for your table column to display the model object in that way. The cell is part of the View layer—the V in MVC.
The C in MVC sits in between the Model and View: It's the object that owns the model and is the data source (whether by Bindings or not) of the table view. The table view gets the model objects from this object to feed them to the cell. This middle object is a Controller.
Now i have it!
I've only one Cell for the Content with an ArrayController.
I'm setting the other Informations with -(id)init for each row.
There are 3 Objects: content, status and date, and for each status i display another image (done, undone, ...).
Thank you very much for your Help! I'm trying to finish the Beta for everyone :)