Auto import for Xcode

2019-06-14 22:34发布

问题:

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".

回答1:

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.



回答2:

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



回答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.



回答4:

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



回答5:

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.