Plist basic operations, plist

Source: Internet
Author: User

Plist basic operations, plist

Important Concept: the reason why "can only be read but cannot be written" in some paths

IPhone and ipad

Resouces Folder: it is read-only and cannot be written.

Document and temp folders: readable and writable.

I. Engineering Structure

  

Ii. Source Code

1. header file: PlistManage. h

@ Interface PlistManage: NSObject-(void) resourcePathFileRead; // The Current Project Resource Directory, which is different from the path-(NSString *) docPath in the real machine "sandbox; // obtain the path of the document folder-(BOOL) isDirNeedCreate :( NSString *) dirPath; // determine whether a new directory needs to be created-(BOOL) isFileNeedCreate :( NSString *) filePath; // determine whether a file needs to be created
-(Void) doAdd;-(void) doRead;-(void) doModify;-(void) doDelete; @ end

2. Implementation of some basic functions:

// Obtain the document directory path-(NSString *) docPath {NSArray * paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES); return [paths objectAtIndex: 0];} // whether to create a path-(BOOL) isDirNeedCreate :( NSString *) dirPath {if (NO = [[NSFileManager defaultManager] fileExistsAtPath: dirPath]) {return [[NSFileManager defaultManager] createDirectoryAtPath: dirPath withIntermediateDirectories: YES attributes: nil error: NULL];} return NO;} // whether to create a file-(BOOL) isFileNeedCreate :( NSString *) filePath {if (NO = [[NSFileManager defaultManager] fileExistsAtPath: filePath]) {return [[NSFileManager defaultManager] createFileAtPath: filePath contents: nil attributes: nil];} return NO ;}

3. Add: including creating null files that do not exist.

-(Void) doAdd {NSString * docPath = [self docPath]; NSLog (@ "Current docment path: \ n % @", docPath); NSString * dataFile = [docPath stringByAppendingPathComponent: @ "docData. plist "]; if (YES = [self isFileNeedCreate: dataFile]) {NSLog (@" the file originally does not exist. A new empty file is created! ");} Else {NSLog (@" the file already exists. You do not need to create it! ");} NSMutableDictionary * plistDic = [[NSMutableDictionary alloc] init]; // Add two" single record "[plistDic setObject: @" shanghai "forKey: @ "recordKey001"]; [plistDic setObject: @ "beijing" forKey: @ "recordKey002"]; // Add two "dictionary records" [plistDic setObject: [NSDictionary dictionaryWithObjectsAndKeys: @ "Jack", @ "name", @ "22", @ "age", nil] forKey: @ "dicKey001"]; [plistDic setObject: [NSDictionary dictionaryWithObjectsAndKeys: @ "T Om ", @" name ", @" 33 ", @" age ", nil] forKey: @" dicKey002 "]; [plistDic writeToFile: dataFile atomically: YES]; // completely overwrite NSLog (@ "added content !! ");}

Running result:

   

A new file is generated under the corresponding path:

   

The content is as follows:

    

4. Read

-(Void) doRead {NSString * dataFile = [[self docPath] stringByAppendingPathComponent: @ "docData. plist "]; // read all content NSDictionary * dic = [NSDictionary dictionaryWithContentsOfFile: dataFile]; NSLog (@" complete content: \ n % @ ", dic ); // read the first "dictionary record" NSDictionary * dicValue = [dic objectForKey: @ "dicKey001"]; NSLog (@ "read the first" dictionary record ": \ n % @ ", dicValue); // read the" sub-element "NSLog (@" reads the "sub-element" in the "dictionary record" of the first layer ": \ nname = % @ ", [dicValue objectForKey: @" name "]); // read the" single record "NSLog (@" reads "single record" at the first layer ": \ nrecordKey001 = % @ ", [dic objectForKey: @" recordKey001 "]);}

Running result:

    

5. Modify

-(Void) doModify {NSString * dataFile = [[self docPath] stringByAppendingPathComponent: @ "docData. plist "]; NSMutableDictionary * dic = [[[NSMutableDictionary alloc] initWithContentsOfFile: dataFile] mutableCopy]; // modify" single record "NSString * city = [dic objectForKey: @ "recordKey001"]; city = @ "shanghai-new"; [dic setObject: city forKey: @ "recordKey001"]; // modify the "dictionary record" NSMutableDictionary * personInfo = [dic objectForKey: @ "dicKey001"]; NSString * name = [dic objectForKey: @ "name"]; name = @ "Jack-new"; [personInfo setValue: name forKey: @ "name"]; [dic setValue: personInfo forKey: @ "dicKey001"]; // write the file [dic writeToFile: dataFile atomically: YES]; NSDictionary * dicResult = [NSDictionary dictionaryWithContentsOfFile: dataFile]; NSLog (@ "Modification result: \ n % @", dicResult );}

Running result:

    

6. Delete

-(Void) doDelete {NSString * dataFile = [[self docPath] stringByAppendingPathComponent: @ "docData. plist "]; NSMutableDictionary * dic = [[[NSMutableDictionary alloc] Protocol: dataFile] mutableCopy]; // Delete" single record "[dic removeObjectForKey: @" recordKey001 "]; [dic removeObjectForKey: @ "dicKey001"]; // Delete "dictionary record" // Write File [dic writeToFile: dataFile atomically: YES]; NSDictionary * dicResult = [NSDictionary dictionaryWithContentsOfFile: dataFile]; NSLog (@ "Modification result: \ n % @", dicResult );}

Running result:

   

Obtain directories:

Http://www.cnblogs.com/ios-wmm/p/3299695.html

To operate plist files under a Resource, you can use the following code: Read-only, not write

-(Void) handle {NSString * plistPath = [[NSBundle mainBundle] pathForResource: @ "resourceData" ofType: @ "plist"]; NSMutableDictionary * data = [[NSMutableDictionary alloc] handle: plistPath]; NSLog (@ "resourceData. plist file information: \ n % @ ", data );}

Iii. "sandbox principle" of ios programs"

Simulator location in xcode6:

/Users/wuxiaofeng/resource library/Developer/

Three basic directories:

  

Principle:

A) When iTunes synchronizes with the iPhone, it backs up all Documents and Library files.
B) when the iPhone is restarted, all tmp files will be discarded.

Reference: sandbox, path acquisition, file operations

Http://www.cnblogs.com/dyllove98/archive/2013/07/30/3225955.html


What are the PLIST list and GLIST list?

1. Is it necessary for ordinary users to upgrade the hard drive? If yes, under what circumstances is it recommended to upgrade Firmware?
> For general users, there is no need to upgrade the hard disk firmware. minor defects can be solved using patches in the software. Unless there is a problem with the adapter compatibility or make up for some hardware defects, the manufacturer will launch the Upgrade Program (including all or part of the patch upgrade ). Here we will focus on the patch. the patch is highly targeted. Not every product of the same model applies the patch. Improper upgrades may cause serious problems.

2. How do I upgrade the hardware firmware? What is the same as Firmware for upgrading a DVD, that is, the principle and process similar to updating a new BIOS?
> The SCSI hard disk Upgrade Program in the PC is only a program that transmits the Upgrade Code. It sends the Upgrade Code to the hard disk buffer and then allows the hard disk DSP to run the Upgrade Code, when the Upgrade Code is running, execute the upgrade process and modify the corresponding area of the EEPROM. At this time, the Upgrade Program enters the status monitoring process.
The reason why FIRMWARE is different from that of EEPROM is clear.

3. Will the manufacturer update Firmware constantly, just like upgrading the driver? In this case, I would like to discuss in depth the role of Firmware...
> The manufacturer will continuously upgrade Firmware and apply it to new products, but the manufacturer will not publish FIRMWARE publicly, it will only be provided to you when the manufacturer determines that your hard disk needs to be upgraded. Of course, the manufacturer will not take any responsibility for the consequences of the upgrade. FIRMWARE functions. For example, the hard disk control panel is a computer, and FIRNWARE is an operating system. It includes many modules: Driver, control, decoding, transmission, detection ......

Low-level formatting may not be unfamiliar to everyone. Many scsicard BIOS has a small tool that can be done, but if I ask you how much formatting is done, you cannot answer it, can you see the progress like checking the disk? The answer is yes. But let the hard disk FIRMWARE one by one BLOCK execution formatting, found that bad track will put him into the P--LIST, the grid is complete does not need to verify, save more time, the rest is just a status monitor.

Since FIRMWARE of the hard disk is used for formatting, several hard disks can be formatted together without occupying system resources. One State monitors the progress of all their devices, saving everyone time.

This feature is actually a hard disk firmware function. You can start formatting it. You can also use a computer to do other work. As long as the power is continuously on, the hard disk will be completed until the task is completed, during this period, the task cannot be terminated even if you unplug the signal line.

When talking about low-level formatting last time, it involves the issue of the defect list. After reading many posts here, we still do not have a clear classification of the defect list. The actual defect list is divided into four categories: 1 PLIST, 2 GLIST, 3 CLIST, 4 DLIST.
Only by clarifying the differences between these lists can FIRMWARE be better compiled to manage their own hard disks and maintain their own data.

1. PLIST: the list of basic defects is the defects found by manufacturers using specialized testing equipment. These defects are permanent defects generated after the magnetic media life is complete and cannot be canceled by non-manufacturers, you can only use a special device to add it. Because there is a GLIST, there is generally no need to move it, so the list of GLIST in the new sales disk of some manufacturers is not empty.

2. GLIST, growth defect list, defects found during hard disk operation, which can be found during formatting, it can also be automated (that is, the FIRMWARE automatic format process mentioned above) or use reassign block (the operation code is 0X07, as shown in the above example) commands are found during the reallocation process.

3. CLIST: Check List, which contains the list found during operating system formatting. It is also stored as GLIST,

4. DLIST: a list that can be defined manually. This list is defined first, and the list of defects that are finally transmitted to the hard disk by the system. The list is displayed in the formatted ....

I would like to ask, how is your comappleBootplist set?

This is mine, for reference only
<? Xml version = "1.0" encoding = "UTF-8"?>
<! DOCTYPE plist PUBLIC "-// Apple // dtd plist 1.0 // EN" "www.apple.com/DTDs/PropertyList-1.0.dtd">
<Plist version = "1.0">
<Dict>
<Key> DSDT </key>
<String>/Extra/dsdt. aml </string>
<Key> SMBIOS </key>
<String>/Extra/smbios. plist </string>
<Key> Kernel </key>
<String>/mach_kernel </string>
<Key> Default Partition </key>
<String> hd (0, 7) </string>
<Key> Hide Partition </key>
<String> hd (0, 6) hd (0, 5) </string>
<Key> GenerateCStates </key>
<String> YES </string>
<Key> GraphicEnabler </key>
<String> Yes </string>
<Key> EthernetBuiltIn </key>
<String> Yes </string>
<Key> GeneratePStates </key>
<String> YES </string>
<Key> Graphics Mode </key>
<String> 1366x768x32 </string>
<Key> GraphicsEnabler </key>
<String> Yes </string>
<Key> Kernel Flags </key>
<String> busratio = 18 maxmem = 4096 </string>
<Key> PciRoot </key>
<String> 0 </st ...... remaining full text>

Related Article

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.