When should I use NSURL instead of NSString and vice versa?

后端 未结 2 936
感动是毒
感动是毒 2020-12-16 20:22

This is not a question about a pertinent problem. It\'s a question by which I try to deepen my understanding of Objective-C or more specific Cocoa Foundation.

When d

2条回答
  •  悲哀的现实
    2020-12-16 20:57

    Generally for path related operations you should prefer NSURL over NSString because the path information can be stored more efficiently in NSURL (according to the class reference for NSFileManager). So I would recommend that for your APIs you use also NSURL.

    Also NSURL has URLByAppendingPathComponent: and URLByAppendingPathExtension: so convenience is served as well :-)

提交回复
热议问题