简体   繁体   English

如何获得我的Xcode项目文件的较短路径

[英]How to get a shorter path to a file of my Xcode project

I have to share my OS X app, all the paths I have used for files used by project are linked to my username and the structure of my computer. 我必须共享OS X应用程序,我用于项目使用的文件的所有路径都链接到我的用户名和计算机的结构。

Is there a way to have paths related to my project so that once my project is shared the user may not get in troubles caused by 'file not found'. 有没有一种方法可以使与我的项目相关的路径,以便一旦共享我的项目,用户就不会因为“找不到文件”而遇到麻烦。

I would move the used files of the project, into the project but then I don't know how to let this happen: 我会将项目的使用过的文件移到项目中,但是然后我不知道如何实现:

actual paths, what I use now: 实际路径,我现在使用的是:

/Users/???username???/XCode/projectName/fileName.txt

what I would like to use in my code: 我想在代码中使用什么:

function(path: fileName.txt)

how don't know how to make the paths this short, not caring about the users directories since the files I'm going to use are all inside my project. 为什么不知道如何使路径这么短,而不关心用户目录,因为我要使用的文件都在我的项目中。

I am very confused. 我很困扰。 Thank you. 谢谢。

There is actually an easy way to read files from your project directory: 实际上,有一种简单的方法可以从您的项目目录中读取文件:

NSError *error = nil;
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"filename" ofType:@"txt"];
NSString *dataContent = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:&error];

So in dataContent you have the content of the file as an NSString instance. 因此,在dataContent您将文件的内容作为NSString实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM