Auto import for Xcode
Asked Answered
T

5

23

Is it possible for Xcode to auto import the frameworks and class headers automatically?

What happens is that every time I build, I will encounter errors due to missing import. I know how to fix, but I felt Xcode can be more intelligent by perhaps giving me an option to "Auto fix imports".

Tiberius answered 24/2, 2011 at 8:17 Comment(3)
Is this real? I cannot believe I cannot auto import a class that I have already defined!Homicidal
Can I ask you to review the answers once again and check if one of them satisfies your question?Arsenical
None, there is no possible answer because I think Xcode doesn't support this.Tiberius
B
5

At the moment it's not possible to do that. I suppose what you want is something like Eclipse's auto-import, i.e. when you first use a class in code, it auto-imports the package.

You should open a bug report here to let the Apple people know about it.

Bibliopole answered 24/2, 2011 at 9:15 Comment(4)
Yes that's exactly what i want. A feature, not bug.Tiberius
Yeah, coming from eclipse where command completion of a class adds the "import" is great. I wish they had it. Sometimes I wonder if it's worth trying Jetbrains AppCodeTwenty
Used AppCode for a while, now I'm back to Xcode. AppCode is great at editing the code, however it feels alien on the Mac. Plus debugging with it is a pain. Also, for Core Data and xib editing you need Xcode anyway, so ...Bibliopole
Yeah, that's about what I was guessing. Thanks for the feedback about it.Twenty
U
5

I know the question is old, but it is good to know that @import was added to LLVM with XCode 5. It gives you features that you wanted. You can find more here and here

Umbrian answered 20/9, 2013 at 12:27 Comment(0)
M
3

You can import a class header into all files automatically by adding it in the .pch file. You will still need to add the frameworks manually though.

Maricruzmaridel answered 24/2, 2011 at 8:47 Comment(2)
I edited my question, because what I seeking for is to auto fix build errors due to missing imports. I don't think adding all headers to .pch is a good solution.Tiberius
It's a very bad advice. Adding a lot of imports to pch will lead to slow and often recompiles in case of changes in those headers.Airstrip
B
2

AppCode has the auto import feature. In my opinion it's not an Xcode replacement, but a welcome addition. It has some killer features like multi caret editing, refactoring that actually works, auto import, tabs that don't drive me nuts, structured code view, etc. Give it a try, you owe it to yourself.

Backgammon answered 9/3, 2015 at 13:13 Comment(0)
W
2

If you install Alcatraz (package manager for xcode) then you can search for "Auto Importer" and you should be good.

Wilke answered 29/5, 2015 at 18:33 Comment(1)
Note that a search for "Auto importer" is now empty. The plugin is called "Auto-importer".Retaliate

© 2022 - 2024 — McMap. All rights reserved.