Xcode: Multiple targets in same bundle - xcode

I have an Xcode project with a Cocoa application target and a shell tool target. These projects share a Core Data persistent store and thus I am hoping to have both projects use the same *.mom file.
To allow this and to simplify deployment I would like the terminal app to to placed inside the Cocoa app bundle and then have both executables access the same *.mom file from inside the bundle.
Is it possible to setup the Xcode project so that the terminal app gets placed inside the Cocoa app bundle and then have the terminal app load the main bundle of the Cocoa app to get the path of this shared *.mom ?

You should be able to do what you want.
Make the Cocoa app target dependent on the terminal app target: click on the Cocoa target, Get Info, General Tab, and click the "+" under the Direct Dependencies pane, and select the terminal target.
Add a "Copy Files" build phase to your Cocoa target: right-click on the target, Add -> New Build Phase -> New Copy Files Build Phase. You'll get an information window where you can pick the destination of the copy; I recommend "Resources", the default.
Drag the terminal app build product (from the "Products" folder in the project navigation pane) onto the Copy Files build phase you just created. This will cause the terminal app to be copied into the Cocoa app's resource folder, which is where your .mom file lives by default, at build time.
In your Cocoa code, you can find the path or URL to the terminal app by querying the main bundle for the path to the resource with the terminal app's name and extension. Your terminal app will need to discover the directory that it is launched from to find the .mom file in the same directory.
Hope this is helpful.

Related

How to include support documents in xcode cocoa app?

In iOS version of app, sample/template files are added to Xcode in a group and then become a directory of that name within the app bundle. Easy enough.
What is the Cocoa equivalent? When I try the same thing, Xcode (Swift 3) fails on build with a "Command /usr/bin/codesign failed with exit code 1". How does one add support files (or directory of files) to a Cocoa app?
In macOS, I guess you mean that, every App creates a Resources Folder inside the NSBundle. Just check with right click "Show Bundle Content".
If you add resources to Xcode, just by dragging the file anywhere in your project navigation, will be asked to copy that file if needed.
I usually create a group with Supporting File, but thats arbitrary, because it has nothing to do with the file structure inside the project folder on disk nor with the product package.
To create groups just right mouse and select group.
This copies the file inside the Xcode project Folder. And if you choose to add target, then the file will be included to that Resource folder.
You can ask for that File with:
let bundle = Bundle.main
let path = bundle.path(forResource: "Test", ofType: "txt")
Edit
if you have to code sign your resources, then ope the copy files menu in Build Phases, add with the plus button your resource and check code sign on copy. This should provide a proper signing for your resource.
Hope it helps!

XCode 4 accidentally deleted product file

I'm using XCode and Appcode for developing.
In Appcode, accidentally I deleted the .app file from the Products folder.
After that I can build the project successfully in both IDE, but can't run on simulator or device, when the build finished, nothing happening.
The .app file created on the derived data directory fine, like earlier so that's not the problem.
If I check the debug scheme in XCode, on the Executable list None is chosen, if I browse the generated app in the derived data directory and set that, then works fine, run on simulator and device too, but the app file not shown in the Products folder and after a restart, XCode set the Executables back to None, which is annoying.
How can I set back the .app file to show in the Products directory in XCode and work like earlier?
I was able to delete the "product" file in my own test project by going to the Project Settings and then clicking on the app under "Targets" and touching the "Delete" key.
To create a new Target, go back to Project Settings and click the "Add Target" button.
Normally, this means you need to reset all of your settings, but if you have the original target's Info.plist (settings) file around, you may be able to pick up some of your previous target's settings from there.
I also faced the same issue.
If we are building for the SIMULATOR - then the Target file still "not-included". Change from the top build actions for - ProjectName>iOS Device (instead of the ios Simulator) then the project target file gets generated and is included in the project folder hierarchy.
There is no need to run - just rebuild and that should do the trick

How to debug a bundle in XCode?

I wrote a nice little program. At some point, it is required to load a bundle with some additional functionality. I, too, am the author of the bundle, so I have the source code and Xcode-projects for both the main application and the bundle.
Until now, I simply dragged the bundle into the resources-folder in the main application, which works fine for running it, but I can't debug it (and of course there is an error in it).
Is there a way to set up Xcode so that I can debug the bundle?
In your bundle project, you should add a custom executable. That executable will launch in the debugger when you do a Build & Debug.
To do this in Xcode 3, right-click on the Executables section in the Groups and Files list in your project and choose Add > New Custom Executable…
You can then select your application in the open dialog.
In Xcode 4, you need to go to Product > Manage Schemes, select your Debug scheme and in the Info tab for the Debug action you should use the Executable popup to choose a custom executable.
You will also need to change your build settings for your Debug scheme so that the build products are placed in your application's plug-ins folder when the plug-in is built, so that when you Build & Debug the application contains the latest version of your bundle.

How to get .app file of a xcode application

I have created an xcode project. Now I want to give .app file to my friend to use that application. From where do I get this file? How to install this .app file in his Applications folder using an installer package?
You can find the .app file here:
~/Library/Developer/Xcode/DerivedData/{app name}/Build/Products/Deployment/
Credit for the path location goes to this answer
SIDENOTE: I had a lot of fun trying to get this into my iPad after that. It worked however. Using Snow Leopard + Xcode 4.2 + iPad with IOS 5.1.1 :) - I used the iPhone configuration utility to get the app into the ipad (you have to add the app, then click on the device, then click "install" behind the app you just added in the "application library" of iphone configuration utility) and had to create a Distribution Provisioning Profile and get the WWDR certificate and finally change the build settings in Xcode after all the certificates were in place. See here
But after much fun I am now looking at my first app on my iPad :) - btw, for getting apps into the app store you need to create a app store Distribution Provisioning Profile, while for ad hoc installs like these you create an ad hoc one. There is a bit more to it, but I think these are the most important and tricky steps. Enjoy.
PS. Just remembered that you also have to set the build type (top left of Xcode) to "iOS device", otherwise it will never sign your application. So the path name above only has limited value: yes, it will have the .app file in it, but no you can't upload it (at least not using the iPhone configuration utility) since it is not code signed - you will get an "Could not copy validate signature" error. So change it to "iOS device" and build (remember to select the right certificates in the build section of Xcode as per the url info above). In that same build section, you can also set the "Installation Build Products Location" to a different path, so that you can determine where the .app (the one that is properly code signed) ends up.
Xcode 12.5
Can be found in the following directory ->
~/Library/Developer/Xcode/DerivedData/{app name}/Build/Products/{scheme}-iphonesimulator/{app name}.app
Build a release version, and the .app file is under build/Release folder of your project. Just copy it to Applications folder of your friend's machine. I don't think you need to build a installer.
xCode window tab
Organizer
Right click to the archive you want to get app
Show in finder
Right click to (ProductName….). xcarchive file
Show package contents
Products
Applications
Finally - THERE IS YOUR .APP PROJECT FILE !
The application will appear in your projects Build directory. In the source pane on the left of the Xcode window you should see a section called 'Products'. Listed under there will be your application name. If you right-click on this you can select 'Reveal in Finder' to be taken to the application in the Finder. You can send this to your friend directly and he can just copy it into his Applications folder. Most applications do not require an installer package on Mac OS X.
Under Xcode 4.5.2, you can find the .app file in this way:
Select Window > Organizer in the Xcode's menu(or just press 'Shift+Command+2')
Select your project on the left side of Organizer, and you will find the Derived Data path on the right side. Just click the mini arrow in the end of the path, this will open Finder at the path.
In the Finder, click "Build > Products > Release", you will find the .app.
I know as for Appium Mobile Automation you need .app file to run ios app on Simulator.So as like me many of you face this problem.
So I explain how to create that .app file and where it is located.
1.Open Xcode.
2.Click on your sample project.(If you don't have then click on create new xcode project)
3.In left panel inside screen you will see products folder then click and expand that, you will see the list.
Then right click on .app file and click on Show in Finder and thats your .app file. Now you can copy or use that path in capabilities for appium desktop or in framework.
Xcode 8.1
Product -> Archive
Then export on the right hand side to somewhere on your drive.
In Xcode 7 a quick way is to use Product > Archive. It's probably not a signed copy for submission but it's good enough to give to somebody else for testing.
In the navigator (left pane), expand the group "Products" and right-click on the .app file and choose "Show in Finder". There it is! :)

Bundle framework with application in XCode

I am an XCode novice. I am trying to follow these instructions. Clearly I am missing something because while I can see that the framework I want has been copied into the app bundle, I can't reference it.
When I start the application from a machine other than mine (or if I remove OpenCV from /Library/Frameworks/ ) I get the following error:
Dyld Error Message: Library not
loaded:
/Users/david/Library/Frameworks/OpenCV.framework/Versions/A/OpenCV
Referenced from:
/Users/g/Demo/Slates/ClipSplitter/build/Release/ClipSplitter.app/Contents/MacOS/ClipSplitter
Reason: image not found
There is no user "david" on my system if that makes any difference. Also this is a prebuilt OpenCV downloaded from the internet. (Here’s a screenshot of the project as requested in comments.)
When the OpenCV.framework has been build it has been configured to use an install path of /Users/david/Library/Frameworks/.
Since you want to use the library as a private framework (installed in the application wrapper at ClipSplitter.app/Contents/Frameworks/OpenCV.framework) you have to change its install path. This can be done easily using the terminal as follows:
$ install_name_tool -id #executable_path/../Frameworks/OpenCV.framework/OpenCV <your_path>/OpenCV.framework/OpenCV
Of course you have to adjust the path of the last argument.
Now, when linking your application, your modified framework tells the linker that dyld has to search for the OpenCV.framework in the app wrapper of your application (in the ClipSplitter.app/Contents/Frameworks directory).
Now you have to copy the OpenCV.framework to your application wrapper. You can do this as part of your build process by adding a copy files build phase: Right-click on your target, select Add->New Build Phase->New Copy Files Build Phase. Select "Frameworks" from the "Destination" pop up and close the dialog.
Your target will now contain a new phase to which you can add the OpenCV.framework by dragging the icon from the Project Navigator on the left side of Xcode window. Note that Xcode won't allow you to add a folder to the Copy Files phase by using the '+' button so in order to copy the framework you'll have to drag&drop it.
You need to set the build setting "Installation directory" to #executable_path/../Frameworks
See the chapter about Embedding a Private Framework in Your Application Bundle in https://developer.apple.com/library/content/documentation/MacOSX/Conceptual/BPFrameworks/Tasks/CreatingFrameworks.html
Regards
Using Xcode 5, you can facilitate this using the Build Phases panel of your application target.
The default appearance of this panel is
By pressing the "+" button underneath Copy Files, you can add your framework as a file that will be copied into Frameworks in your app bundle.
Now, when you build, your Framework(s) will be copied into your bundle.

Resources