iOS development--Data Persistence OC & File System Summary

Source: Internet
Author: User

File System SummaryPackageSystem

Is the app itself, is actually a zip package, the resources/executables are in it

    • + (NSBundle *)mainBundleGet 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 *)nameYou 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.