The difference between stringbyappendingpathcomponent and stringbyappendingstring
stringByAppendingPathComponent
- NSString * FilePath3 = [Documentspath stringbyappendingpathcomponent:@ "Dictionary"];
Stringbyappendingstring
- NSString * FilePath = [Documentspath stringbyappendingstring:@ "/hello.txt"];
Comparison of the two
1, the latter need to add "/", the former does not need to add
2, the former path print out:/users/mymacbook/library/developer/coresimulator/devices/c1b4afe9-2058-40a6-b868-101e166ff961/data/ Containers/data/application/79cb8a9f-1000-4360-a9ea-801adf1e0044/documents/database.sqlite
The latter path is printed out:/users/mymacbook/library/developer/coresimulator/devices/c1b4afe9-2058-40a6-b868-101e166ff961/data/ Containers/data/application/79cb8a9f-1000-4360-a9ea-801adf1e0044/documents
stringByAppendingPathComponent
is to link the previous path format with the normal string format that follows, and return in the path format.
For example: Get the Program home directory NSString *path =nshomedirectory (); The obtained path is "/root/user/";
Path = [path stringbyappendingpathcomponent:@ "Abc.txt"], and the latter path is "/root/user/abc.txt".
The difference between stringbyappendingpathcomponent and stringbyappendingstring