将 NSString 附加到 NSURL?
我有一个 NSURL、一个文件路径,我想在其末尾添加一个 NSString(文件名),我该怎么做?但在这之后我不希望整个事情都是一个 NSURL 吗?
谢谢。
I have an NSURL, a file path, and I want to add an NSString to the end of it (the file name) how can I do this? But after this is don't I want the entire thing to be an NSURL.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为这是一个很好的解决方案:
在 Swift 中你可以执行以下操作,
你还可以声明 URL 是否是一个目录,
I think it's good solution:
In Swift you could do the following,
You can also state whether the URL is a directory,
我认为这很简单:
I think it's as simple as:
如果您有一个指向目录的文件 NSURL,并且您希望最终得到一个包含 NSURL 路径并附加文件名的 NSString,请使用:
您还可以使用
URLByAppendingPathComponent
但这会增加一个额外的内容创建不需要的额外 NSURL 对象的步骤。If you have a file NSURL to a directory and you want to end up with a NSString containing the NSURL's path with a file name appended to it, use this:
You can also use
URLByAppendingPathComponent
but that adds an extra step which creates an extra NSURL object that isn't needed.