How to suppress the "dead store" compiler warning on Xcode? - objective-c

How can I suppress the "dead store" warning on a single file in Xcode?
I tried
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-value"
without luck. Any suggestions?
BTW, I don't want to "fix" the code, because I'm creating a bunch of objects only for the sake of inserting them into a Core Data database. I don't want to do anything else with them at the moment.

Although it doesn't work for the whole file, you can silence individual warnings for dead stores by adding
(void)variable;
after the line causing the warning

Related

Adding Swift or Enable Modules = YES on an Objective C project causes build errors

In Xcode 7.1 after adding a single swift file to a large Objective-C project, build fails with many "No visible #interface for XYZ declares the selector ABC" and "method definition for ABC not found" errors.
All these errors appear in one file only.
Adding a swift file automatically changed the build setting "Enable Modules" to "YES". Changing this back to "NO" results in an error free build, but prevents mixing with swift.
The problem was an errant #import "header.h" in the middle of the file. This was probably left over from some copy and paste in the past.
Seems that when enabling modules the compiler sees this header and marks the objective c class' #end at this point, meaning all method implementations after this were not being seen.
Due to my compiler setting of all warnings being treated as errors, I never saw this issue as the compiler stopped outputting errors after the max number had been displayed.

Is it possible to squelch build warnings for certain files/classes?

I am currently building a project with msbuild that contains generated code. Is it possible to squelch build warnings from specific files (preferred) or classes?
If you have control of your code generation process you can use pragma statements in the code to suppress warnings.
At the top of the code you want to suppress warnings, add
#pragma warning disable
then at the end of the code add
#pragma warning restore
Note: In most cases you will want to suppress only specific warnings. You do that with
#pragma warning disable warning-list
where warning-list is a comma-separated list of warning number without the prefixes.
Another option is to suppress specific warnings across the whole project.
See How to: Suppress Compiler Warnings

ARC migrator returns error in other target

I'm trying to convert an older project to ARC. My project relies on Cocos2D, which is a 3rd party non-ARC library. All the Cocos2D source files are part of a separate target and are compiled to a static library.
However, the ARC migrator returns ARC semantic issue errors in Cocos2D source files, even though they're not part of the main target I'm trying to convert.
What could be the reason for this? That source code shouldn't matter, right?
In general, the safest thing is to not perform ARC conversion on code that is not yours. Therefore, you could just tell the compiler to not use ARC with the Cocos2D code, by going into your "Build Phases" on your target's settings, add the -fno-objc-arc flag as described in the Transitioning to ARC Release Notes. You just expand the "Compile Sources" section of the "Build Phases", double click on the Cocos2D source files, and then enter -fno-objc-arc in the pop up box.
Having said that, I appreciate that there might be a lot of .m files involved. As such there are sources out there that suggest different approaches to tackling Cocos2D and ARC, such as Enable ARC in a Cocos2D Project.

IOS 5 Arc Is it still a good practice to release your object as soon as you are done.

I am using the NSXMLParser and would like to release some of the objects as soon as I am done with them in the parsing. However, I am not sure if that would mess up the automatic reference counting in IOS5 ? Is that a bad practice to release the objects asap in the code in IOS5 when you are done with them?
Few things, one of them should be your answer:
in an ARC project you can't call retain or release. A call to those methods will produce a compile time error, so you really cannot do any manual memory management any more.
on the other hand you can turn ARC on and off on a per file basis. That's very easy to do- open the project settings, click on "build phases", open the "compile sources" strip, then select the desired .m file and hit "enter" on the keyboard - in the popup window enter "-fno-objc-arc". Close and re-start Xcode (they still have a bug with this, so ... ). Now ARC is disabled for this file - you can use retain and release in the code and everything
however there's also another way to go - use a release pool. In general if you are about to consume lot of memory and you wanted it released faster you should use a separate memory pool, it's very easy to do that and the new iOS5 way looks like this:
#autoreleasepool {
// code code code code
}
So, all the allocations happening between the curly brackets will be released when you get out of the block - there you go :)

XCode Syntax Coloring Broken

XCode frequently seems to lose it's mind, and doesn't color code system classes or provide correct "code sense" suggestions. This is endlessly frustrating. The question has been asked on at least three other occasions:
Problems with Xcode Syntax Highlighting
xcode code sense color/completion not working
Xcode: code loses syntax coloring
I have switched by project version to/from 3.1-compatiable and 3.2-compatiable, completely restarting XCode before and after each change with no effect.
I have rebuilt the code sense indexes and completely restarted XCode with no change.
I have built my project to make sure there are no errors and restarted.
I have copied my files (sans .svn files) to a different location - same problem.
I've already completely disabled the argument "placeholders" because they screw up my documents when i type too fast... all I'm asking for is for the "esc" key to display the correct list of properties and methods.
You should clean your project's derived data. They are likely corrupted.
Go to Organizer > Projects > Your_Project > Derived Data > Delete
Xcode will reindex your project and you should be back to normal.
For anyone interested; my app has some precompile directives:
#if ...
Turns out there was an error in one of these sections.
I'm assuming my app built fine because these sections were stripped out before they ever got to the compiler... but CodeSense doesn't care about these (it still wants to color code everything inside these) - so CodeSense would puke all over the place because of the error, even though I didn't find it when I tried to build the app.
Once I fixed the error within that block of code, my coloring returned.
Would be nice if XCode just greyed out those sections instead of dying.