Is there any way to compile a single file in Xcode 5? - xcode

I'm talking about a functionality such that you can just quickly open a .cpp file (C++ console application, nothing regarding Apple ecosystem), work on it, compile and run, without all the project creating mumbo-jumbo. When I open a file with code, all the "Product" options are greyed out for me but after some googling, I found posts claiming that Xcode 5 was to be the first one offering such functionality. Has it been implemented and it's just available elsewhere or were they false rumors and you still have to create a project and import a file there?

Or if you want a shortcut: CTRL + COMMAND + B.

In the top menu of XCode "File - Edit - View" you will see Product.
Click Product->Perform Action->Compile "myfile.xxx"
If you want a shortcut for that command, click XCode -> Preferences-> Key Bindings and set one up.

Related

Xcode 6.4 Doesn't List Targets or Groups for Project

I'm working on a project and went to add a new file, but the Finder window is different than the usual window when adding a file. When I go File->New File->Cocoa Touch Class->Set up name, superclass and language, I get this:
This is only the case for Objective-C files. For Swift files I get the usual window where I can choose the target membership and Group I want the file to be in
Well this sounds like a great bug to report at bugreport.apple.com . Not much we can do other than wait for the next beta and hope they solve it then.

Is there a way to save open Xcode tabs?

Is there a way to save the current 'workspace' in Xcode and/or create keyboard shortcuts for different workspaces? Not the workspace as xcode defines it (https://developer.apple.com/library/ios/featuredarticles/XcodeConcepts/Concept-Workspace.html), but rather the open files and split panels etc.
Yes, there is a way. You can "Create Snapshot" from the File menu. Give the snapshot a name. The next time you open XCode it should be in the state you left it.
Actually, scratch that. I just tested and it's not even necessary. If I open multiple tabs and then close Xcode, when I reopen Xcode the tabs are still there. Is that what you mean?

SDL and SFML not working with Xcode 5

I got used to VS quiet well, but hopped to Mac. OS X is fantastic, and I'm playing with Xcode now. I do not like it... For Apple related stuff it is great, but God, SFML and SDL are not working! I got same problem with both! I installed Command line Tool, and installed both Frameworks and everything, made templates, but when I build my main.cpp, it get's broken in same place. On the line #import <Foundation/Foundation.h> it says can't find Foundation/Foundation.h, and I tried adding path, and fiddling all the things in build phase, but still nothing. It is so frustrating! I can't wait for JetBrains to release their C++ IDE. Can anybody help me with these? I tried recompiling SDL2, since it was crashing Xcode but then I got that Foundation.h is missing. SFML is showing me the same thing, even if I created template and everything else is perfect. Can anybody help me?
It sounds like you need to add Foundation.framework to your Xcode project. To do that:
Click on your project's icon in the Project Navigator pane. This will show you the various targets in your project. (There's probably only 1 if you've just made the project.)
Click on the target you're trying to build, then click the "Build Phases" tab.
Twirl open the section named "Link Binary With Libraries" and click the "+" button. It will display a dialog with a list of the standard frameworks. There's a search box at the top. You can just type "Foundation" and it will find it.
Select it, and click "Add". That should add it to your target.

Cmd + click doesn't work on new project from existing source

I'm using xcode 4.6.x and creating a blank project in C and adding existing files to it.
When all files are added, the cmd + click navigation doesn't work, stating a "Symbol not found" error.
Does anyone have a clue of what is going on?
Btw, I did try the solution suggested in Xcode code sense and cmd+click to symbol doesn't work for 1 of my projects, but it's not effective.
I had the same issue with Swift project w/ CocoaPods.
Try this:
Click on your scheme -> Manage Schemes -> make sure that Container for your scheme is set to your Workspace
P.S.: fixes no Quick Help issue as well
Does your blank project have a target defined, and do the added modules belong to it? I've seen cmd+click not work inside modules that didn't belong to the target.
Try this steps
1) Open "Organizer"
2) Click "Projects" tab
3) CLick "Your Project" at left column
4) Click "Delete" on Derived Data line
5) Restart Xcode

A way to automatically organize #imports in Xcode

I love the "Organize Imports" command in Eclipse to implicitly add and remove classes imported into a source file (as in Java or ActionScript).
Is there a command in Xcode to update the #import directives at the top of.m Objective-C files based on the classes referenced within the file?
You can do this by creating an Automator action and use that in Xcode as well as everywhere in Mac OS X. To do that, do the following:
Start Automator -> New
Choose "Quick Action" (or "Service" on older MacOS/Automator versions)
add a "run shell script" action
use sort | uniq as the script and check the "output replaces selected text" checkbox
save and give it a name (e.g. "sort & unique")
check "Output replaces selected text"
After you saved it, you can just select your imports in Xcode, right click and choose your "sort & unique" action to organize your imports.
This is not as good as the organize import actions in Eclipse or IntelliJ, because it doesn't removes unused stuff etc. but it's better than nothing.
PS: Got that from WWDC 2012 Sessions - Session 402 Working Effeciently with Xcode (starting at 6:15)
EDIT
I started using AppCode, the Objective-C IDE from JetBrains, and it has features like "organise imports". You should check it out: http://www.jetbrains.com/objc/.
I'm resolving this as not currently a feature of Xcode :(
I've found Cedar Shortcuts to at least be usable. It's not as good as Eclipse's import feature (it doesn't organize imports), but it can keep you from having to go to the top of a class file and typing an import statement. With this plugin you just place the cursor on the class that needs imported and press Ctrl + Option + I. Here's the github project. https://github.com/cppforlife/CedarShortcuts
I made a small Xcode plugin to sort the headers and remove duplicates of the file with a shortcut, you can check it out! - https://github.com/insanoid/CleanHeaders-Xcode
AppCode from Jetbrains can do this.
Yup. Like in Eclipse, this would be an awesome feature since developing in XCode (Cocoa Touch) does require quite a bit of class imports which are not easy to remember and Android development in Eclipse sorts this out with a simple keystroke combination that saves so much time ! Hope there is a way to do this in XCode soon !
WordService (freeware) from Devon Technologies, provides a service that can be used in any Cocoa app that can (amongst others) sort lines.
Alternatively, you can use an Xcode Extension, such as Imp
Swiftlint has an opt-in rule which if opted, will automatically sort the imports alphabetically.
Add - sorted_imports to your .swiftlint.yml file under opt_in_rules.
Run swiftlint autocorrect terminal command on project root directory (same where swiftlint.yml is stored).

Resources