I have an app that I want to use to store different people's data. For example, say you add person A, B, C to a table; then when you tap on them you can add more of their data - phone number, address etc.
I want to be able to store the info for every one of those entries in order to be able to display them when the app starts next time (and when I switch between the different table entries). Currently if I add data to a person's details, if I switch to another person, the data for the first one goes away as I'm not storing in any way.
I don't want to use Core Data as it's only for a low number of entries (about a dozen or so). Can anyone please give me an idea of how I could store each entry so as to pull it at run time (or whenever I tap on an entry that I've added details for already)?
Store each entry in an NSArray of NSDictionarys, which, in turn, can be stored in NSUserDefaults.
Related
In my app I have to send a Lat/Long to my server and in return I get an array of Data within the range of 10-15m and I have to add the people on the map. I can achieve this by few different scenarios:
1- I can load all the Data within the range of 100m and only make a request if user searches outside this range.
2- I can use the method "startUpdatingLocation" whenever user searches for a location and when user is on that location I can call "stopUpdatingLocation". The Last location will be saved and used to send for the request.
3- Or I can keep the location updating and when user clicks on the button to make the request I can get the last lat/lang.
They might sound similar but I want to know which scenario saves less memory and data usage.
It depends on how often the users are performing searches, and if their searches are geographically close to one another. Approach #1 uses more memory because it has to store a larger array of data (which, depending on what the data looks like, probably isn't a very big deal) but it might save data usage in the long run if you have to perform less queries to your server. It depends on user behavior.
Approaches #2 and #3 don't seem to be any different in terms of data usage and memory since you are describing different ways of keeping the latitude and longitude of an user updated. This doesn't seem to be related to the data usage of your server.
I have a requirement in which locally created events have to be synced with sever synchroniously. To explain this briefly lets consider this scenario, there were two events occurred in the offline app called A and B here A > B. In this case B should sync only when A is completed its sync.
To fix this I must have an extra attribute in my entity to identify which is created earlier. This attribute can maintain either created time or any incremental number.
Here only i am facing some clarifications
Solution :1 Based on created time
If I maintain created time in that attribute, Will it be proper for below scenario
Lets say I created on event “A” today then I changed my device’s date to previous day’s date and then I am coming back to my app and creating an another event “B”. Here which one will be earlier? if app says “B” is most recently inserted object then there is no issue I can stick with this solution itself otherwise I need to move to some other solution. Is there any optimised solution to find inserted order by maintaining created time?
Solution :2 Based on incremental number
I believe core data does not provide any auto-incremental id so we need to maintain it manually. If so what would be the better approach to maintain the maximum assigned value? Will it be good if I store the maximum assigned value in NSUserDefaults? Whenever app creates an event the value will be fetched from NSUserDefaults and +1 will be added and then I will assign final value to the event. Is this approach proper one? or else please guide me if you know any better solution
There is no auto-incrementing number built into Core Data as that is more a business logic specific item. However, it is not difficult to implement.
You can store the last number used in the metadata of the persistent store. During your insert, simply increment that number, add it to each entity as you go. When you are done inserting, update the number in the metadata.
That is how Core Data updates its own insert numbers for the objectID.
What is more efficient? Divide the data into more connections or just put it all into one big connection?
Lets say we have a tableview which show a name of a person, when you select one row you move to another VC which show more info and in that view you can press a button to get even more info about that person.
Is it better to on the first VC to download ALL information for EVERY person in one big json and then use that to load the next views.
Or is it better to download on the first view just the names and maybe an id. And when you select a row you send that id to the server to download more info about just that person and so on.
My practical experience is that connections sometimes doesnt succeed so more connections could be dangerous, but the other way you only download the data you need.
What is the preferred method?
In my opinion best practice is to lazy load. Make connections as and when they are necessary.
I take your point about 'connections failing' and, to a certain extent, that's true of mobile connections. However, in addition to a slower user interface, another caveat of 'one big download' is the fact that potentially by the time the user interacts with the data it's stale.
Imagine my app as a list manager. On first launch, you have one empty list. You can add as many stuff in it as you want for free, but if you want more lists, you have to buy an In App Purchase. I have two types of IAP : you can purchase lists one-by-one, as a consumable item (which you can't transfer to another device), or purchase an "unlimited lists" item (non-consumable), which lets you add as many lists as you want, and all yourd devices benefit from it. Note that I will probably disable the first one if you bought the second one.
To handle this, I use a global var through my app. The variable represents the maximum number of lists you are allowed to have. At first launch, the value is "1". If you buy a single list, the value becomes "2", and so on. If you buy the "unlimited pack", the value is set to "-1". So if your current number of lists is less than what you're allowed to have, you can add new lists.
I need to save this value locally somehow, so for example if the user bought the unlimited pack, he can keep adding lists when he comes back in the app.
What is the best way to securely save this value ? I usually use NSUserDefaults but I'm not sure one can't change the values manually. Also, storing them online is not an option as you can use the app offline.
If you think my way of handling the IAP with this variable is not the right one, please don't hesitate to tell me how you'd do it. Thanks.
You can save it into iOS Keychain.
There is a library that helps dealing with it: https://github.com/ldandersen/STUtils/tree/master/Security
So, to save number of lists, you'll use it like
[STKeychain storeUsername:#"lists"
andPassword:#"1"
forServiceName:#"my_super_app"
updateExisting:YES
error:&error];
To retrieve:
[STKeychain getPasswordForUsername:#"lists"
andServiceName:#"my_super_app"
error:&error];
My app has it's own sql database with let's say 2000 rows.
I know that in future I will add some new and delete some old. Each row got prioritet parameter that changes in order of user interaction.
I want to store all prioritets locally so my future app updates would not erase them.
So the question is what is the best way of doing that? Remember that I will need fast access to those prioritets in future and they must be easily mutable.