Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting rid of redundant #import lines

Tags:

objective-c

In my Cocoa development, every so often I include a header into a source file so I can use a particular class in it. But then later I delete that code from the source file, and forget (or don't really want to worry about) deleting the corresponding #import.

With time, a lot of redundant #import lines pile up in my source files, throughout the codebase.

Now, I know that these lines cause no harm, but is there any easy way to get rid of them automatically? At least it would make the top of every file cleaner ;)

like image 334
Enchilada Avatar asked Jul 02 '11 23:07

Enchilada


People also ask

What does it mean to eliminate redundancy?

Avoiding Redundancy. Redundancy occurs when a writer unnecessarily repeats something. Writers should avoid. redundancy not only because it distracts and annoys readers but also because it adds unnecessary. length to one's writing.

Why should redundancy be removed?

Limitations of data redundancyCreates opportunities for data corruption: Data corruption occurs when something damages or causes errors in the information during the storage, transfer, or creation process. This means that storing several copies of the same data can create more opportunities for its corruption.


2 Answers

There's a tool that does this for C and C++, but as far as I could tell, it doesn't yet support Objective-C. I've filed a ticket to ask for that.

like image 72
Peter Hosey Avatar answered Oct 19 '22 23:10

Peter Hosey


nothing comprehensive off the shelf comes to mind.

1) JetBrains' AppCode may help. It's quite young at this time (e.g. not even 'beta', but it is publicly distributed), and doesn't fully understand structures of includes and nontrivial xcode projects and build settings, but it is likely smart enough to handle simpler cases.

2) you could create some scripts to accomplish what you're after. it wouldn't be terrible if you already have a project which builds out everything using common build settings. doing this manually is a pain, and is usually not a good use of time in larger projects if you are not using a high level of automation.

like image 34
justin Avatar answered Oct 20 '22 00:10

justin