// 1.拼接字符串
NSString* homePath = NSHomeDirectory();
// 简单拼接字符串
NSString* docPath1 = [homePath stringByAppendingString:@"/Documents"];
// 拼接路径,自动中间加"/"
NSString *docPath2 = [homePath stringByAppendingPathComponent:@"Documents"];
// 拼接扩展名,文件后缀,自动中间加"."
NSString *docPath3 = [homePath stringByAppendingPathExtension:@"Documents"];
// 格式化拼接字符串
NSString *str = @"Documents";
NSString *docPath4 = [homePath stringByAppendingFormat:@"/%@", str];
NSLog(@"---%@", docPath1);
NSLog(@"---%@", docPath2);
NSLog(@"---%@", docPath3);
NSLog(@"---%@", docPath4);
输出结果:
2015-11-26 20:19:22.608 01-plist存储[3822:360712] ---/Users/zh/Library/Developer/CoreSimulator/Devices/8EE05444-0DC3-49F7-A827-DCE72186F069/data/Containers/Data/Application/42691849-97D7-49C7-89AB-C0713B655D08/Documents
2015-11-26 20:19:22.608 01-plist存储[3822:360712] ---/Users/zh/Library/Developer/CoreSimulator/Devices/8EE05444-0DC3-49F7-A827-DCE72186F069/data/Containers/Data/Application/42691849-97D7-49C7-89AB-C0713B655D08/Documents
2015-11-26 20:19:22.609 01-plist存储[3822:360712] ---/Users/zh/Library/Developer/CoreSimulator/Devices/8EE05444-0DC3-49F7-A827-DCE72186F069/data/Containers/Data/Application/42691849-97D7-49C7-89AB-C0713B655D08.Documents
2015-11-26 20:19:22.609 01-plist存储[3822:360712] ---/Users/zh/Library/Developer/CoreSimulator/Devices/8EE05444-0DC3-49F7-A827-DCE72186F069/data/Containers/Data/Application/42691849-97D7-49C7-89AB-C0713B655D08/Documents