屬性列別 plist檔案:這個檔案可以儲存陣列,可以吧陣列中的元素儲存這個檔案中

將陣列的資訊,儲存到plist檔案中,就會將陣列的所有元素儲存到這個檔案中

 - (BOOL)writeToFile:(NSString *)path atomically:(BOOL)useAuxiliaryFile;

plist檔案中的資料還原成一個數組

 + (nullable NSArray<ObjectType> *)arrayWithContentsOfFile:(NSString *)path;

//    獲取doc路徑

//    1.拼接字串

//    NSString *homePath = NSHomeDirectory();

//    NSString *docPath = [homePath stringByAppendingString:@"/Documents"];

//    NSLog(@"%@",docPath);

//  下面這個不用/ 來拼接方法  - (NSString *)stringByAppendingPathComponent:(NSString *)str;

//    NSString *homePath = NSHomeDirectory();

//    NSString *docPath = [homePath stringByAppendingPathComponent:@"Documents"];

//    NSLog(@"%@----",docPath);

//    2。用第二中比較科學,因為第一種必須是要用Documents

//    通過搜尋通過搜尋  FOUNDATION_EXPORT NSArray<NSString *> *NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory directory, NSSearchPathDomainMask domainMask, BOOL expandTilde);

NSString *docPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];

NSString *filePath = [docPath stringByAppendingPathComponent:@"Property List.plist"];

//    陣列

NSArray *array = @[@"123",@"good",@"zzhuangx",@"裝逼如風"];

    [array writeToFile:filePath atomically:YES];

NSLog(@"%@",docPath);


下面這中的也可以

#import <Foundation/Foundation.h>

int main(int argc,constchar * argv[]) {

NSArray *arr =@[@"ddd",@"srose",@"lili",@"luck"];

    [arr writeToFile:@"/Users/moyan/Desktop/abc.plist"atomically:NO];

//    出來Yes的時候,桌面上會出來abc.plist檔案

NSLog(@"Yes");

for (NSString *strin arr) {

NSLog(@"%@",str);

    }

//    NSArray *arr = [NSArray arrayWithContentsOfFile:@"/Users/moyan/Desktop/abc.plist"];

//        for (NSString *str in arr) {

//            NSLog(@"%@",str);

//        }

//    

return0;

}