What is the best way to save/retrieve array in iOS PG - objective-c

i have an array of results based on calculation of other arrays of texts entered by the user.
i want to save the array as user clicks on "save results" button.
So i want to know what is the best way to do this.....NSUserDefaults or Databsase, or PList or
and how to save the array by that way.
Actually i have to use NSUserDefaults for that according to my project need
Please help me..

Look into Core Data. It's performant, typically uses less memory than other options, gives you persistence for free.
There are lots of references on line that can help you get started. Try this article by Ray Wenderlich as a start:
http://www.raywenderlich.com/934/core-data-tutorial-getting-started
A Google search can give you many more.

I usually just write the array to file
using
[array writeToFile:myOutputFile atomically:YES];
Here is a reference link.
http://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/NSArray.html#//apple_ref/doc/uid/20000137-BABCGEFF
you can also load them from file with
[array initWithContentsOfFile:myInputFile];
here is another reference link
http://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/NSArray.html#//apple_ref/doc/uid/20000137-CBHBDFEE
just make sure that the output file is located in a writable location for your application.
Note
Normally a good starting point on an object is to get a brief overview of the functions for that object so you know what that object can accomplish.
Hope this helps.

Related

How to save an object after exit

So I'm currently working with VB.net and winforms and I need the have objects created from my classes saved so they are still there if I exit the program and open it again.
I also needed to make them dynamically so I was going to add them to a dictionary on creation and save that dictionary in the settings, but it seems that you can't save a dictionary in settings.
So how can I do this? Maybe something like save the creations in an excel sheet and recreate them on load each time, that might work but seems a tad inefficient, Thanks in advance, Ed.
(p.s. sorry if this makes no sense it's 1:30am in the morning here and I'm not really with it.)
So just putting this here in case anybody else has this problem, I took Plutonix's advice and looked into serialization and it sorted my problem, used this video: https://www.youtube.com/watch?v=oN_YHn3EVOs

Realm database performance

I'm trying to use this database with react-native. First of all, i've found out that it can't retrieve plain objects - i have to retrieve all of the properties in the desired object tree recursively. And it takes about a second per object (~50 numeric props). Slow-ish!
Now, i've somehow imported ~9000 objects in it (each up to 1000 chars including titles). Looks like there is no easy ay to import it, at least it is not described in docs. Anyway, that's acceptable. But now i've found out that my database size (default.realm) is 3.49GB (!). The JSON file, which i was importing is only 6.5mb. I've opened default.realm with Realm Browser and it shows only those ~9000 objects, nothing else. Why so heavy?
Either, i don't understand something very fundamental about this database or it is complete garbage. I really hope i'm wrong. What am I doing wrong?
Please make sure you are not running in chrome debug mode. This is probably why things seem so slow. As far as the file size issue goes, it would be helpful if you posted your code to help figure out why that is happening.

MBXMapKit using local .mbtiles database file

I would like to use MapKit (on osx) to display custom map tiles from a .mbtiles (sqlite) database of the sort exported from TileMill.
MBXMapKit looks great, and is almost what I'm looking for. I could see how, with very little modification, MBXMapKit could be tweaked to point to a local .mbtiles database file.
Is there any way to use the MBXMapKit framework to accomplish this without tweaking? I did read the docs, and couldn't find a straightforward answer. I did find a private method on MBXOfflineMapDatabase called -initWithContentsOfFile: which sounds promising and looks like it does what I need -- is there anything to watch out for if I expose and use that method?
Alternate option is to subclass MKTileOverlay and use -loadTileAtPath:result:, which is easy to do, but also requires managing the connection to the sqlite file etc.
Have a look at this for the latest on MBTiles support:
https://github.com/mapbox/mbxmapkit/issues/3
It'll be coming probably in the next release. This should be distinct and separate from both the normal performance cache (NSURLCache) as well as the (also SQLite-backed) offline databases, which are meant for individual tile downloads being placed into a cache one-by-one.
It took me quite some time to work this out, but here is the link that got me on the right path.
https://github.com/mapbox/mbxmapkit/pull/110/commits/8b9fbf3fd56ae804a38c737305f128fd43a8225d
For some reason the method _mbtilesOverlay = [[MBXMBTilesOverlay alloc] initWithMBTilesURL:mbtilesURL]; can not be used on the latest version of MBXMapKit. I just replaced the .m and .h files with the files in the link, and used MBXViewController.m as a guide to get the map view to show the tile overlay.

Best strategy to read file only once at launch?

I am reading a file datafile at the launch of my application.This is just self learning drill.
On apple developers website under the heading Minimize File Access at Launch Time
it says
If you must read a file at launch time, do so only once.
So my question is that is there a standard or preferred way of doing this. At the moment I have an instance varible NSArray and I populate that in - (void)viewDidUnloadand never garbage collect it. Is that good enough ? or Should I be making use of application Object (I am not even sure if it is logical to say this.).
There is no standard way to optimize. But there are some guidelines.
One basic idea of optimization is to do less. E.g. as the advice you cited where the data of a file may be needed at multiple points in your code, it is better to read it from disk once and then distribute a data pointer within your program.
If the file is big enough to cause a stutter when you start your application, i.e. it takes more than 20ms to read and parse the file, you should consider reading the file in a background thread/task and adding a ‘loading…’-state to display to the user.

Make a video from an NSArray of NSImages

I know this has been asked before, but the only answers I have found use UIImages. I need to make a 25 fps video from an NSArray of NSImages in Objective-C. Could somebody give me a link to the documentation dealing with this (if there is any), or tell me how I can do it?
NOTE: I will also need to know which frameworks to use if there is no documentation on this. And, before you ask, I have done lots of searches for the documentation.
You can do this with QTKit by creating a movie and adding images as frames. See the "Creating a Single Frame-Grabbing Application" section. Step 13 specifically demonstrates how to add an image (and have it last a specific duration in the movie ... should probably last more than a single frame for, say, stop-motion stuff).