Use Core Data With UITableView With Sections That Have A Different Number Of Cells - ios

So I have a TableView contains sections that can possibly hold a different amount of cells depending on the user input for rows for detail. I trying to learn more about saving and want make a simple app that allows the user to save recipe ingredients. For example I can have 5 different sections containing 5 different types of food like -> banana: amount-2 Calories-10 Details-Slice, Apple amount-3 Calories-20 Details-Mash <-. The User would then click done and his or her recipe name will be saved and displayed on a cell in another table view. Once the user clicks on it he/she can see what he/she put and can edit it if he/she desires. I was told that Core Data would be best for this type of saving.
How could I save all the info in a organized way. I know how to save individual cells using Core Data but what is hard about this is each section can contain a unique number of cells and then this data is all saved into one data entry. It's like an array inside of an array inside of an array. I also have a feeling that I have to use dictionaries. I can't seem to structure all of this data. Can anyone help or have any tips on how I should attack this? I'm using Swift by the way.
Picture of what one section of the TableView might look like:

There's several ways you can tackle this situation. The first solution that came to mind was storing a unique array for each section that you want to display. E.g. a fruit array, vegetable array, etc. If you did this, when you fetch from Core Data you would store the items in the appropriate arrays and do something similar to the following within your numberOfRowsForSection:
switch (section) {
case 0:
return fruit.count()
case 1:
return vegetable.count()
default:
return 0
}
That switch statement will be called according to whichever section you are in at the time. If you went with a different route like a dictionary, instead of returning the count of the different array, you could return typeDict.objectForKey("fruit") instead.

Related

In Google Sheets return all cells that contain string

I've seen a lot of similar questions where users want to returns all rows that contain a specific value, but I'd like to only return the cells that contain the value.
Basically, I have one sheet that has a bunch of categories in different cells, on the second sheet I'd like to return every category that contains a "_". I tried =QUERY(cat!A:Z,"select * where B contains '_'"), but that returns the whole row, I just want every cell individually.
Thanks for any suggestions!
Try this one:
=TRANSPOSE(SPLIT(
ARRAYFORMULA(CONCATENATE(IF(REGEXMATCH(Sheet1!A:Z,"_"),Sheet1!A:Z&"~","")))
,"~"))
You may use some rare symbol, like ~ to join and split the result, so it shows in one single line.
Data sample
Result

Saving parseable string into core data

I 'm developing an uitableview based application which sections and rows numbers for different selecions are determined by the data from core data. Now i need a structure for keeping user's choice.
To be clear, its an password saving app and users can save their informations according to pre installed templates. As seen in the images below, different key value pairs, for wireless router and instant messenger selections, are shown in the table view. I keep rows information for different types in core data so that rows can be loaded dynamically according to values from core data...
The application is for one user. User can change the values of a any row including the row in title header, "wireless router" value for example... After a user make some changes in the rows' value and click "Save" bar button at top right, a third tab will be added to below and will display this new data modified by the user.
My question is how should i keep the new data modified by user?
My core data structure is;
A solution comes in my mind is to keep values as a parseable string in a table, which is "SavedData" in image above.
What approach can be more suitable to solve what i need. Is saving key value pairs into one table as parseable string sth proper and efficient? or is there a better way.
NSUserDefaults is a versatile solution. It accepts NSArray, NSData, NSDictionary, NSNumber, NSString. There are many different ways you could model this. If you expect the app to have multiple users you could store Dictionaries of usernames, passwords, url. If the use case is only one single user than something like this should work fine. Top line is to save and bottom line is to read from anywhere in the app.
[[NSUserDefaults standardUserDefaults] setObject:usernameTextField.text forKey:#"flickerUsername"];
NSString flickerUsername = [[NSUserDefaults standardUserDefaults] object ForKey:#"flickerUsername"];

Set each sections of tableview with different query data from Parse

What I am looking to do is have 2 sections in my tableview which I can do by specifying 2. From there I am stuck. I am performing 2 queries from Parse to gather the details I need. 1 query gather extremely urgent data and the second is data about less important events. Each query has its own array so I am thinking it should be pretty easy to accomplish.
How do I set the first section to the urgent array (self.urgent) and the second to the less important events array (self.event)? I know how to configure cells for a single section with an array but have never had to configure 2 section with different results.
Thank you in advance.

Automatically updating Data Validation lists based on user input

I have a very large data set (about 16k rows). I have 10 higher level blocks and within each block I have 4 categories (10 rows for each) which use Data Validation lists to show items available in each category. The lists should automatically update based on user input. What I need your help with is that I want to use the same data set for each block and preferably a least calculation/size intensive approach. I have put together a sample file that outlines the issue with examples.
Sample File
Thank you for your help in advance.
Okay, I've found something, but it can be quite time consuming to do.
Select each range of cells. For instance, for the first one, select B3:B18 and right click on the selection. Find 'Name a Range..." and give it the name "_FIN_CNY". Repeat for all the other ranges, changing the name where necessary.
Select the first range of cells to get the data validation, and click on "Data validation", pick the option "Allow: List" (you already have it) and then in the source, put the formula:
=INDIRECT($G$4&"_CNY")
$G$4 is where the user will input. This changes as you change blocks.
_CNY is the category. Change it to _CNY2 for the second category.
Click "OK" and this should be it. Repeat for the other categories.
I have put an updated file on dropbox where you can see I already did it for the data of _FIN for categories CNY, CNY2 and INT and did the one for _GER as well. You'll notice the category of INT for _GER doesn't work, that's because the Named Range _GER_INT doesn't exist yet.

Display an NSSet/NSMutableSet of different objects in a UITableView

i'm new to SOF and i hope this is a good question to begin with :)
i'm stuck with the following issue:
I need to display a NSMutableSet with the content of 2 different NSArrays containing 2 different object types in the same TableView and also in the same section.
I've tried with an NSMutableDictionary but couldn't figure out how to display the NSArrays stored into the dictionary, the first one and then the second within a sole section.
Thanks in advance.
PS: what i'm trying to do is to display entities like Meals, Foods and Drinks for a specific day in a tableView with grouped cell for each mealtime. So the grouped e.g. for a lunch shows 3 entities: meals, foods and drinks.
I'm getting NSSets of Meals, Foods, Drinks using a relationship to the Day Object. I tried to put them in an 2 dimensional array but failed on loading cells(it shows only the last object).
You can ask the Object in the NSArray for its type with isa.
According to the answer you can prepare the cell in prepareForRowAtIndexpath

Resources