How to access a file from the Xcodes Supported Files group in an application?

I have an application that I almost finished now that emails, at the end of the data input stream, are two .pdf files. One of them is generated from the entered data, the other is a static file, which will be the same in each instance.

The first pdf file is generated perfectly, it is saved in the application documents folder, and I am successfully attached to the email for sending. This is the second .pdf I made from outside the application and am trying to add what causes me grief.

I added it to the Supported Files folder in my Xcode project, but after a long search here and elsewhere on the Internet, I cannot decide how to access this file in order to be able to add it as an email. Having “downloaded” the application data from the organizer in Xcode, I see that the file is not there anywhere; presumably because Xcode can see that the file is not being used anywhere, it does not add it at build time (a very guess on my part), but I don’t know how to reference it anywhere, because I don’t know where it will be link to it!

+6
source share
3 answers

Xcode does not create any folders in your application set that corresponds to groups. Just make sure your pdf file is present in the Bundle copy resources in your target build phases. Then you access your resource in the [[NSBundle mainBundle] bundlePath] .

+9
source

If you want to access the image, this code is a good example, like:

 NSString* imageName = [[NSBundle mainBundle] pathForResource:@"image1" ofType:@"png"]; NSImage* imageObj = [[NSImage alloc] initWithContentsOfFile:imageName]; 
+3
source

In Swift, you can get a bundle-resort with the following function:

 func currentresourcepath () -> String { return (NSBundle.mainBundle().bundlePath + "/Contents/Resources/") } 
0
source

Source: https://habr.com/ru/post/898825/


All Articles