Does Xcode have resolve imports functionality? - xcode

In Eclipse, I rarely have to manually import a file due to its ability to automatically resolve imports using a keyboard shortcut. Is this available in Xcode?

Does that mean automatically add the correct #import lines?
Nope.
On the other hand, Cocoa code tends to just pull in the world. As far as system headers, it's pretty normal to only need <Cocoa/Cocoa.h>, which is already in the template Xcode use for a new file. You can use a prefix header in your project to cover your own headers.

Related

QtCreator doesn't find header files (.h) belonging to my project

I'm using QtCreator to develop a "plain" C++ based software (in particular, this one). By "plain" I mean my software is not using Qt libraries or any other Qt stuff appart from the IDE.
QtCreator version is 4.14.1.
Everything goes fine (building, running application, debugging, etc.) but the editor is reporting problems finding header files (i.e. .h files) belonging to my project, as shown in the screenshoot below:
Interesting to note that system headers (e.g. stdio.h) are correctly found.
So maybe I'm missing some piece of configuration in my project. First thing I thougth was the .includes added by QtCreator at project creation time (fiware-orion.includes in my case), which is like that:
src/lib/cache
src/lib/mongoBackend
src/lib/parseArgs
...
which are the places in which the header files are (e.g. src/lib/mongoBackend/MongoGlobal.h) so everything seems fine in that file...
Any idea or suggestion is really welcomed :)
I think I found the answer myself just after publishing the question (use to happen :)
Adding to the .includes file this line:
src/lib
solved the problem.
It makes sense... as my header names are like mongoBackend/MongoGlobal.h then
src/lib + mongoBackend/MongoGlobal.h = src/lib/mongoBackend/MongoGlobal.h

Xcode sometimes doesn't require imports at the top of the file

I am faced with a strange issue. I recently rebuilt my Xcode project file using a tool called Xcode gen, I now have hundreds of errors in my files related to imports, for example:
import Foundation
struct BillingHistoryDetailTableCellViewModel {
let contentColor: UIColor?
// Implementation
}
error: Cannot find type 'UIColor' in scope
Why am I suddenly faced with this error now? Xcode had no issue compiling this kind of file before.
Is there some kind of setting or flag required to fix this?
Answering this for others:
If your project happens to include objective-c code and the bridge file includes imports to frameworks that use UIKit then this will be imported globally across your project, hence Xcode not asking for the import in files where you reference objects in UIKit.
This seems kinda like a bad side effect of using an objective c bridge as it's easy to miss the adding the import statements.

How do you create a basic TemplateInfo.plist file with Ancestors and specific frameworks?

Whenever I create a new project I add my own class files -often the same ones. It has become tedious to manually create these over and over. I want an automatic way to do this. I discovered custom Project Templates and I'm not sure if they are well documented by Apple.
I can create a cocos2D project with my custom classes and it works wonders. The problem is when I create a basic empty application with my custom classes.
Basically okay I'll give a little context. See my TemplateInfo.plist: This works. Note the "Ancestors" part. Here's how I interpret it: this inherits from cocos2d templates and does things like:
add necessary frameworks
adds cocos2D things like the splash image
other project-specific things
Now I don't know where these ancestor templates are or what format they are in, so I can't yet break down the individual things and say "OK I want the frameworks they include but not the launch image," but that's essentially what I want to do. I want to start with the most basic template and build from there manually.
I discovered that I can add specific frameworks in the "Targets" area. But before tackling that, I have a question: What Ancestors do I use, so that it does not use the Cocos2D base templates? I want the most basic thing.
1) Try removing all Ancestors and create a new Project and Xcode won't let you name the project and it crashes.
2) Try including only the Ancestors for the Default Empty Application: com.apple.dt.unit.cocoaTouchApplication
And it adds the correct frameworks:
Foundation
CoreGraphics
UIKit
XCTest
which is cool. However I noticed it overrides my Prefix.pch with a [Project-Name]-Prefix.pch and my project does not compile because I include a Debug Logger statement in my custom Prefix.ch like this:
#ifdef DEBUG
#define DLog(...) NSLog(__VA_ARGS__)
I figure this is the "com.apple.dt.unit.cocoaTouchApplication" ancestor doing its thing, and I want custom behavior that's different.
Is there a list of Ancestors somewhere that I can look at? Or is there a way I can look at the specific settings defined in "com.apple.dt.unit.cocoaTouchApplication" (if that even makes sense)?
Has anyone else run into this? What techniques do you use? Does anyone wish for an easier way to do this? Or is it better to create files manually every time?
I'm spinning wheels and any insight would be helpful. Thanks.
I figured it out. Searching through Xcode's default templates, I found one that uses basic ancestors. I used the following two:
And in Targets you can easily add the frameworks you want to include:
There are many little quirks like how to include an Info.plist file and Prefix.pch file and how to get it to rename properly (and replace the default one placed by the template). I am creating a video tutorial to show all these things in detail.
Creating your own custom templates is quite satisfying. Saves a lot of time and hassle when beginning new projects.

Frameworks are missing in Unity generated Xcode project

Some of the frameworks are missing when I generate Xcode project through Unity. What would be the reason? How can I solve this?
I mean manually I have added them in Build Phases to fix the error, but why are they missing?
They're missing because they are required when you use those APIs.
If you're coming from a language like Java this might seem strange, but with Objective-C (which is ultimately C) you need to let the compiler know where the APIs come from beyond just the header file import.
Unfortunately, Unity doesn't provide any support for specifying additional frameworks for your Xcode project to link to. However, if you can you should generate and modify your Xcode project once and then subsequently always have Unity update rather than override the project.

Mac - Adding CoreGraphics.framework, for CG use in a C header

Xcode 3.25, Mac OS X 10.6, 10.5 compatibility required.
I have a Mac Xcode project, which mixes Cocoa and C/C++. Some legacy modules require a C-only header.
I created a C header file: myCTypes.h
I wish to use a CGPoint in that header.
Compiling generates an error: CGPoint is not defined. OK, no problem, so I'll just:
#include: "<CoreGraphics/CoreGraphics.h>"
Unfortunately, I get this:
error: CoreGraphics/CoreGraphics.h: No such file or directory
Hmm. OK, so I'd best add the framework. But if I right-click on the frameworks group within Xcode, and try to "Add an existing framework", CoreGraphics does not show up in the list. Grr.
So I try to add it manually, navigating my way to System/Library/Frameworks. Nup, not in there either.
So I look in the 10.5 SDK paths, and once again, there's a lot of CoreXXX frameworks in there, but no CoreGraphics.framework.
Can someone please tell me what I'm doing wrong here? What do I need to use CGGraphics in that header? Cheers.
EDIT
This was solved by:
#include <Carbon/Carbon.h>
(But if anyone wants to tell me if this is good practice or not, please feel free. Cheers.)
Core Graphics is part of Application Services, so that's the header you should include:
#include <ApplicationServices/ApplicationServices.h>
You can include Carbon.h if you want, but its total length after preprocessing is very long, so you should include it only when you absolutely have to (e.g., for Carbon Events hotkey stuff) in order to keep your build times down.
Well i know this topic is super old but i wanted to answer pqnet`s question in the comments (can't comment on it because I have less than 50 rep points :( )
now to the point: Yes, today anyway, you can add only core graphics framework if you like.
Click on your project in the project navigation pane; build phases; link binary with libraries. Then, chose coreGraphics; then click add.
Thats all, enjoy.
I managed to include some of the functions required by my project with this:
#include <CoreGraphics/CGWindow.h>
But I guess other functions are in other headers under CoreGraphics
Additional info:
Catalina
Xcode 11
PS: if some of Apple guys read this, please, add headers in your documentation!! And examples!!

Resources