File System SummaryPackageSystem
Is the app itself, is actually a zip package, the resources/executables are in it
+ (NSBundle *)mainBundle
Get the bundle class of the program itself. NSBundle provides a number of path-related functions
- Run-time read-only, non-writable
- There is no need to create subfolders, Apple does not recommend creating subfolders in the package
+ (UIImage *)imageNamed:(NSString *)name
You can load the picture files in the package directly
- There is not too much data in the package, otherwise it is not conducive to user installation
- NSBundle Pathforresource:oftype: Use this function to find the file that the package is stored in
SandboxSystem
After each app is installed in a separate directory, this directory is called a sandbox, the directory structure is as follows
- Documents
- Library/caches
- Library/preferences
- Tmp
- Program Bundle
Documents are automatically backed up when the user is backed up via itunes, and other directories are free
- Nshomedirectory () Get the app sandbox directory
- Nstemporarydirectory () Get $ (sandbox directory)/tmp
NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES)
Get $ (Sandbox directory)/documents (the function returns an array)
NSSearchPathForDirectoriesInDomains( NSLibraryDirectory, NSUserDomainMask, YES)
Get $ (sandbox directory)/library
NSString defines a bunch of join,split functions for file paths, and the path correlation functions are mainly defined in: NSPathUtilities.h files
NsuserdefaultsSystem
- Nsuserdefaults *defaults = [Nsuserdefaults standarduserdefaults];
- File stored in $ (sandbox directory)/library/preferences/{bundle identifier}.plist
- iOS provides a factory function, no capacity limit, it is best not to store business data inside, which will undermine the semantic settings of iOS, which should be stored in the program settings related information
KeychainSystem
- Focus on storing passwords or certificates
- The data is encrypted and stored
- The information stored in the keychain will not be lost due to the deletion of the app and remains valid after the user re-installs the app.
CacheSystem
It's really the cache, the storage will have an expiration time
- Nsurlcache, the URL is a unit, can exist on the hard disk
- Nscache, only in memory, and nsmutabledictionary difference is not small, meaningful is: iOS can release itself during the program run time Nscache
Fileformat
- Binary: NSData
- Plist: The most common and simple
- Serialization of objects: Nskeyedarchiver
- SQLite: File database, Core Data/libsqlite3/fmdb
- Plain text: Rare, with standard C library operation, Fopen/fwrite/fclose
iOS development--Data Persistence OC & File System Summary