Deploy a Swift OS X app locally? - xcode

I am not new to programming, but I am new to Swift. I have developed a small app that I have no intention of distributing, I just want to use it for myself. Everything works just as desired in XCode and now I want to deploy that app locally. How can I run my app on my machine without needing to have XCode also running? I just want to see my app in my Applications folder and run it when I want. Does XCode put build files somewhere that I can access them and use outside of XCode?

On the Product menu there is an Archive option. Select that to create an archive of your app.
Xcode should then automatically open the Organiser window with the archive of your app selected.
You'll see a big blue button called Upload to App Store on the right with two smaller buttons below it. The one you want is called Export... Press it and you'll get a pane giving you various export options with different kinds of signing.
The bottom option creates an unsigned .app file which you can put in your Applications directory.
NB As Eric D says, you can just drag the app out of the products directory, but unless you edit the scheme, that will give you a debug build with less optimisation and with asserts activated.
Update for Xcode 11.2
As Bell B. Cooper points out, the process has changed slightly. Now when you archive an app, you get a window listing the apps and a big blue "Distribute" button. Pressing this, gets you a dialog box giving you the various options. Which one you choose depends on what you want to do with the executable. With Catalina, unless it's just for your own use, you probably want to go for one of the options that involves signing the app.

Edit: while this answer still works, it targets old Xcode versions and uses the debug version of your executable. For recent Xcode versions, and for using the release version of your executable, see JeremyP's answer.
Each time you build an OS X application with the current scheme, Xcode automatically populates the "Products" folder with the related app bundle.
You can find this folder in the Project Navigator:
Xcode > Project Navigator > "Products" folder
Your .app is in there and ready to be used and/or copied to the /Applications folder.

Related

How to run Swift Terminal app on another Mac

This is my first Swift app. Most of my coding experience is in C++ and C#, but I’m fairly new at programming.
I made a Terminal app, called PhotoSorter, using Swift. After building it, I pulled the executable out of the product folder in Xcode and ran it. It works great on my own laptop, but when I try to run the executable on another Mac, I get the following error:
“The alias ‘PhotoSorter’ can’t be opened because the original item can’t be found.”
Question: How are you supposed to create a Swift executable in Xcode that can be ran on any other Mac? Ideally, I want something that the end-user can just right-click/double-click to open.
Looking at your question again, I see you're using Xcode. In that case, the best way to distribute your program is to choose "Archive" from the "Product" menu, and when your app is done building, click the "Distribute App" button in the window that appears. Then you can choose your code signature and create a code-signed version of your app (or distribute via the App Store if you're into that sort of thing).
The immediate answer to your question, though, is that you're making an alias instead of copying the file. I assume you've used the mouse to drag and drop out of Xcode's "Products" pseudo-folder. The default action when you do that is to make an alias (which is like a shortcut on Windows). You can override that by holding down the Option key while you drag, but it's better to go the Archive route.

tvOS Invalid Toolchain when Submitting tvOS 9.1 app

I'm trying to submit a tvOS app through iTunes Connect, and every time I try I get the following message:
Invalid Toolchain. New apps and app updates must be built with the public (GM) versions of Xcode 6 or later, and tvOS 8 SDK or later. Don't submit apps built with beta software.
I have made sure to update Xcode to it's newest App Store version, and I'm not using any beta software.
While I never ended up resolving this issue completely, I did find a workaround.
When submitting an app, iTunes Connect checks the compiled app's compatibility to the latest operating system (in this case, for tvOS 9.1 build 13U85). While compatibility is completely fine between the two, Xcode has a bug. During the archiving process, Xcode specified my archive as Build 13U78 which is inaccurate and not correct.
A workaround I found, which is quite simple, changes the archive's build from (in my case) build 13U78 to build 13U85.
First, we'll create an archive which is self explanatory.
Second (and this is essential) we need to do the following:
Open 'Show in Finder'
Next, you need to right-click your archive and choose 'Show Package Content'
Then go to Products, then Applications, then repeat the second step (right click the .app file, then choose 'Show Package Content').
Once you're there, open the Info.plist file.
You'll see some version information in it, but what we want are:
DTSDKBuild
...
DTPlatformBuild
These two options should be something like:
DTPlatformBuild 13U78
...
DTSDKBuild 13U78
Modify 13U78 to be the most recent build of tvOS, or in my case:
DTPlatformBuild 13U85
...
DTSDKBuild 13U85
You're almost done! Just save the modified Info.plist file and close it out. Then Submit to App Store- you're done!
Make absolutely sure you're using the most recent build of tvOS.

Xcode 5 Cocoa App Fails to Load Nib on OS X 10.6

I'm creating a Cocoa application for 10.6 and newer OSs. I created a brand new document-based application in Xcode 5 (10.9) and changed two settings to make it 10.6-compatible: I changed the deployment target to 10.6 and turned Auto Layout off on both MainMenu.xib and xxDocument.xib, the two default nibs that are included with the document-based template. I archived my application (no code signing) adding no other code and tested it on four different OSs. Here are the results:
OS X 10.9: Launches and shows a new document window ("Your document contents here") as expected.
OS X 10.8: Launches as expected; same as 10.9.
OS X 10.7: Fails to launch; Console applications yields "App Name: Unable to load nib file: MainMenu, exiting".
OSX 10.6: Fails to launch; Console yields same as 10.7.
I'm quite baffled as to the behavior of my application. I added absolutely no code to the template document-based app that Xcode created for me; I just changed the required settings to make it compatible with 10.6 and up. I also tried turning off ARC in the build settings, which made no difference at all. I checked Apple docs and also searched for other questions about the console error I received, but none of them were related to this problem. I was very surprised that 10.7 exhibited this behavior, as 10.7 is compatible with ARC. I would greatly appreciate any advice on how I can fix this problem. I would suspect that there is an easy modification to the default template, as Apple probably wouldn't supply a template that requires extensive modification to merely get it working. Thanks.
UPDATE:
As suggested, I turned off base internationalization in Xcode. I ran the app, and it worked fine. I exported the application (no code signing) and tested on all of the above OSs. This time, the error that I received above occurred for all OSs. This even occurred on the SAME machine that I built the project with, the only difference is that I didn't run it from Xcode. My next step was to actually make a MainMenu.xib file (because removing base internationalization deleted the old one) and set that as the main interface. Now not only do I get the error in the exported application on all OSs, but it shows up in Xcode when I try to run the application! Is there something else that I am missing?
AS mentioned before you need to disable Internationalization Base.
In the Project Navigator Click on the on the first item which is your project (denoted by blue page with white A in it, it is the root of all other items)
You should by default see the Info page to the left (if not select it from the tab at the top)
The last item in the Info property sheet is Localization. Under Localization you will have the ability to add and remove languages and you should by default have two already Base, and English.
Delete both, and deselect the check box "Use Base Internationalization"
Once you have done this, remove the any *.xib files you have from the project itself. MAKE SURE TO ONLY REMOVE REFERENCES !!!DO NOT SEND TO TRASH!!!
Once the references have been removed, go into Finder, Open your project directory and you will find a directory called Base.lproj with your *.xib files located in them. Copy or move them one level up to your project directory, and delete Base.lproj directory.
Go back into xCode and add back in your *.xib files. ++K to clean the project, then ++R to rebuild.
This should move the *.xib files in the App Package from Base.lproj (where 10.6 does not seem to find them) to the Resources file folder, and solve the problem.
Newly created Xcode 5 projects have base internationalization turned on. Base internationalization is supported on OS X 10.8 and later. You'll have to turn off base internationalization to support 10.7 and 10.6. See the following Stack Overflow question for more information:
Base.lproj/MainMenu.xib is not available when compiling for targets before Mac OS X 10.8
Another thing you may need to do to support 10.6 is to set the deployment target to 10.6 for both the project and the xib files. I know you said you set the deployment target to 10.6 in your question, but it wasn't clear if you set it for both the project and the xib files. As you're discovering, Apple's project templates do not place a high priority on compatibility with old OS versions.

Unable to build using Xcode 4 - The selected run destination is not valid for this action

So I'm horribly confused by this error, other threads on Stack Overflow mention I should set the SDK, but I see no option to do this. I'm trying to build:http://wafflesoftware.net/shortcut/
And I get no options, and I can only choose My Mac 64-bit, and I want it in 32-bit. Really beginning to hate Xcode 4.
Here is the screenshot when I try to edit my scheme: http://groovyape.com/scheme.png
Thoughts?
Firstly, I have observed that when Xcode 4 decides my Mac is 64 bit and all my other schemes have vanished, a restart of Xcode fixes that.
If you still have the issue after a restart, go to Manage Schemes... (under the Product Menu) and click on Autocreate Schemes now button. Try to delete the other schemes and see if you can run the project now.
However, if the issue is that you need to set the SDK, that's different:
Click on the top-level project icon in the left hand panel
In the right hand panel that appears, select Build Settings (near the top).
Select "All" option (instead of Combined)
Ensure Base SDK is set appropriately, like "OS X 10.7".
FWIW I'm seriously considering reverting to Xcode 3.2.5 at the moment, 4 seems horrendously buggy.
In xCode 4.4.1, use Validate Settings to solve the problem!
I can select either 32bit or 64bit now.
Ran into the same error message ("The selected run destination is not valid for this action") when attempting to use XCode 4 to build/run a tiny Objective-C "Hello, World" project I created in XCode 3.x. Fixed it by choosing to "Manage Schemes..." from the drop-down menu to the right of the Stop button, deleting the one scheme on the list (click checkbox beside the scheme, then click the "-" button at the bottom left), and then clicking "Autocreate Schemes Now".
I also needed to change the "Base SDK" from 10.5 to 10.6, by clicking on 'folder' icon (beneath the Run button), clicking the root/top of the tree view below it, clicking on the blue icon below "PROJECT" in the pane just to the right, and then finally, choosing "Latest Mac OS X (Mac OS X 10.6)" to the right of that.
I had this issue today. I found switching Base SDK from Latest iOS (4.3) to iOS 4.3 fixed everything.
This will happen if XCode believes your mac is a 64-bit machine, when really it's a 32-bit. If this is the case for you, simply click on your project icon from the far-left pane - it's the menu item that displays your project name next to a little blue icon. This should bring up a center pane that says "PROJECT" at the top. Highlight your project name, and the third pane should now show your build settings. The first item is "Architectures" which will allow you to specify if you are building a 32-bit or 64-bit application.
Kind of amazing that none of the answers here solved the issue for me, but I figured it out. Forget restarting Xcode, or using Autocreate Schemes, still only 64-bit will show up as a valid destination in the scheme.
The correct solution is to change the Architecture for your project. Go to Build Settings (in the root node of your project), and change Architecture to 32-bit Intel, it's right above the Base SDK setting. Destination will instantly switch to "My Mac 32-bit". HTH somebody.
It sounds as if you're trying to run (Cmd-R or run button) the framework (which you can't do - it's not an executable, just a library) rather than simply build it (Cmd-B).
I had this issue and maybe it was a coincidence but when I restarted XC4 but this time didn't choose to load my project from the popup window that appears on launch - instead choosing it explicitly from the File menu - the issue didn't occur and the build started ok.
On the 3 or 4 occasions I had this error, I had chosen to load the project from the popup window that appears when XC4 first loads.
As I say, I might have just got lucky, but I certainly didn't make any other changes to the projects to 'fix' the issue.
I found a good practice for moving from Xcode 3.2.X to Xcode 4 is, to remove any references to older SDKs (in the case of Mac OS to remove any Base SDK Ref, etc., for Mac OS <= 10.5, in the case of iOS I think you need to remove everything <= 4.3) PRIOR to upgrading to Xcode 4.
I never experienced any problems for new Projects, created in Xcode 4, only for such that where created with Xcode 3.X or 2.X
Xcode 4.5. I was trying to compile for 10.6. It seemed to be stuck on 64 bit just because it couldn't find the sdk. I didn't get any message about it not finding the sdk.
I first tried to put in the correct path to /Developer-3.2.6/SDKs/MacOSX10.6.sdk but xcode didn't want to find it there. Then I copied that folder into 4.5 next to the other OSX Platform sdk (new location I think just look in the bundle).
And magically my 32 bit came back.
So my conclusion is that the 32/64 bit option is really dependent on whether xcode can verify the sdk that you're trying to use. Being stuck at 64 while trying to compile for 32 gives the error without notifying you that its first issue is that the sdk can't be found.
I fixed this by deleting my xcuserdata in my Project file. Not sure how it got corrupt. But it worked for everyone else in the office, deleting the xcuserdata did the trick. I made sure Xcode was closed while doing so. Just for fun, make sure you delete your DerivedData folder for the app, and do a build clean for superstitious folks.
If this happened after you renamed your app, go to Schemes -> Edit Scheme -> Run <YourApp> -> Info
Select the right executable file (YourApp.app)
Another way is to select None as executable and then reselect the YourApp.app from your Debug-iPhoneOS folder.

Sharing iPhone Apps for the Simulator

iPhone Apps built for the simulator are stored here:
/Users/<username>/Library/Application Support/iPhone Simulator/User/Applications
Is it possible to copy the <GUID>.sb and <GUID> directory and install them on a different computer (with Development tools installed)?
This would be very useful for testing/demoing with out having to buy iPhones for all the managers and external clients.
I found a way that requires just a little more setup, but is much easier for non-developers:
Instructions for your users/testers:
Install Xcode following Apple's instructions
Double-click the attached application - the iPhone simulator will launch, install the app and start it automatically.
How to set it up:
Download and unzip (to a folder on your desktop or wherever) 'Simulator Bundler' from: http://github.com/landonf/simlaunch/downloads
Set your XCode build target to the required Simulator configuration (iPad/iPhone/which iOS version)
Do a 'Build and archive'
Find it: select 'Archived applications' in the Organizer, right click the relevant build, select "Reveal archived application in Finder"
Drag the application (yourAppName, no extension) onto the Simulator Bundler app
Done. This will create a self-contained Mac OS X yourAppDisplayName.app file in the same folder (with your app's icon as the icon) that you can stick up on an FTP server or email to your users/testers.
--
I think it's much neater/slicker than having to explain where to copy files, how to launch the simulator and so on.. And if anything gets messed up they can just uninstall via the familiar tap-and-hold + (x) gesture in the simulator UI, then double-click the app you sent them again.
You can also produce several of these packages changing the bundle identifier between builds, allowing them to be installed side by side in your testers' simulators; say for getting some user feedback on different UI designs, or configure one for Production and one for Staging/QA servers, so your content editors can check their changes before they go live or whatever..
The ability to reinstall the app from a desktop icon is also very convenient for localisation testing: launch the simulator, uninstall the app if present, set the required region format and language, double click the icon on your desktop, test; repeat for each required locale. (guarantees a fresh install each time, I've found that switching language with the app installed can result in all sorts of strange behaviour)
Yes, if you send those files to another person, and they put them into that directory, they can test the applications in the iPhone Simulator as well :)

Resources