Recently asked some about the development of iOS in the processing of data storage, the sense of data storage This is also a frequently used function, it is necessary to organize and record their own.
There are typically four ways to store data in iOS development, namely:
1.NSUserDefaults: Used to save the user's own settings of some properties, the user opened the program again, or after the boot, the information is still present, nsuserdefaults can be stored in the types including Nsstring,nsdata,nsnumber, Nsdictionary,nsarray. If you want to store other data types, you need to convert to some of the previous types before nsuserdefaults can store them.
2.NSKeyedArchiver: In the form of archiving to save data, data objects need to adhere to the Nscoding protocol, and the corresponding classes of data objects need to implement Encodewithcoder: and Initwithcoder: Methods, Encodewithcoder: Used to tell the system how to encode a data object, Initwithcoder: Used to decode a data object. For example, the addition of news categories, and so on once again into the app when added to the classification can be saved.
3.Sqlite Database: SQLite database is widely used in mobile operating system development, when using this database, you need to first add database related libraries and header files, Libsqlite3.dylib, the operation of the database can be operated through a third library, such as Fmdb, an open source third-party library.
4. Write to disk: Get the path to the file to be saved by nssearchpathfordirectoriesindomains this method.
In fact, the way of data storage in iOS development is mainly divided into two types, one is stored in the file, the other is stored in the database. The way to store it in a file, such as Nsuserdefaults,plist,nskeyedarchiver Archive, is just the plist,nskeyedarchiver way to save it in a sandbox, The nsuserdefaults is saved to the sandbox's Library/preferences directory by default. stored in the database this way, you can access the database directly through SQL, or through the ORM (Object Relational Mapping) Object Relational mapping access to the database. Here's a look at how to store it in a database.
SQLite is currently the mainstream embedded relational database, its main features are lightweight, cross-platform, the database is widely used in many embedded operating systems, SQLite database is based on the development of C language lightweight database, in iOS need to use the C language database operations, Cannot use OBJECTIVE-C, because the import of Libsqlite3 is written in C language, using SQLite database is relatively simple, if it is used in Mac OSX, you can go to the official website of sqlite download command line tool, You can also use tools like Sqlitemanager to make databases, and there are a few steps to using the SQLite database in iOS development:
1) First import the LIBSQLITE3 framework;
2)
Ways to store data in iOS development