Issue By Adding NON ARC Files to ARC iPhone Application? - iphone

I added add .h and .m files from an non ARC application to ARC iphone Application. I set -fno-objc-arc as compilerflag in build phases to these files. But when I try running this application after adding these files I am facing a problem. Application does not give any error is just shows failed once and stops the process of building.
I am confused and trying to understand what is the problem in this. After I delete these non ARC files, it is running normally.

First, you add the .h file but don't set any compile flag on it - your comment on this is a bit confusing - in fact your question and comments are confusing. So lets try to sort this out:
you added both the .m and the .h to your project - you can see them in the left pane
the .m file was added to the build phase of the desired target with a compile flag of -fno-objc-arc
Now it gets tricky, as your question is self contradictory:
1) you tried to build and the build failed. So then edit your post and provide the error messages.
2) the build succeeded, you ran the project, but it failed somehow. Problem is you don't tell us how it failed.
So, in addition to clarify your question, please note that if you add a non-ARC file to your project, that file must conform to certain conventions, which you can read about in the ARC docs (two very short articles, one from Apple, one from llvm). For instance, if you have a method in that file that starts with "init" or "create" then whatever object it returns must be retained not autoreleased.
I personally have used non-ARC files with an ARC project for a year now with no problems.

Just do the following thing:
Reset your simulator.
2 . Clear your Build
in your non arc file content remove the release,retain,autoreleasepool and auto release.
After build and run. hope it will work.

Related

NSXMLParser gives EXC_BAD_ACCESS only with ARC enabled

Well, the subject pretty much says it all. I have code to unzip and parse an epub. It works fine if I don't use ARC, but I get a EXC_BAD_ACCESS if I use the same code (without the retains and deallocs of course) with ARC enabled.
The code bombs during the parse method of the NSXML parser.
The code I am running is: http://ideveloperworld.blogspot.in/2011/02/epub-reader.html
You might be thinking, why not just proceed without ARC then, but I am integrating the epub reader into a much larger project that already uses ARC.
Thanks for any help.
If you want some files to be compiled without arc, here's what you need to do.
go to your project (click on the blue folder in the Project Navigator), then go to build phases. Click Compile Sources, which should be a list of files in your project.
For any files that you want to be compiled WITHOUT ARC, Set a Compiler Flag for that file to be: "-fno-objc-arc". It should look like this:

Cannot compile my app with few classes from the Google Mac Toolbox

UPDATE:
Here is more detailed compiler output:
So I am working on a simple app. I want to be able to do some encoding/decoding of strings, so I have added these three files from the Google Mac ToolBox to my project:
GTMDefines.h
GTMNSString+HTML.h
GTMNSString+HTML.m
Since my project uses ARC, I have added the files to the build phases and set the -fno-objc-arc flag so they don't compile with ARC. See the screenshot:
Now I go to my main view controller and add this line:
#import "GTMNSString+HTML.m"
And I try to compile my project. I get errors like these:
How can I solve this? I am new to iOS development so please explain well.
To get rid of the first two warnings (no rule to process file...) remove GTMDefines.h and GTMNSString+HTML.h from your "Compile sources". Only .m-files need to be there.
You never want to import .m files, even if it's technically possible! To get rid of your errors, change your import from
#import "GTMNSString+HTML.m"
to
#import "GTMNSString+HTML.h"

Use Automatic Referencing Count in specific classes in ios

Actually i came to this question when i was trying to add some classes that have been made upon ios prior to IOS 5 and these classes doesn't having ARC and the project i am trying to add is made upon the IOS 5 and it give me the compile time error related to ARC the classes having suck kind of information that if i try to remove the release/retain then it start behaving irregular.That is my problem, Now come to question i want to know that is there any way so that i can mark those classes not to use ARC so that the newly created classes that having base SDK ios5 compile with ARC and i mention not to use ARC simply compiled with their retain/release values.That is the only way i have left i think for making properly this app.
Any idea how i can use those classes that is having base sdk prior to ios5.
Thanks,
the image below will show you how to do it.
-fno-objc-arc flag to disbale arc
-fobjc-arc flag to enable arc
Go to your project settings, under Build Phases > Compile Sources
Select the files you want ARC disabled and add -fno-objc-arc compiler flags. You can set flags for multiple files in one shot by selecting the files then hit Enter key.
Go to Issue Navigator -> Validate project settings -> Perform changes. In this way Xcode automatically remove release and retain keywords from whole project and convert into ARC compatible.

Adding the tag to a ARC enabled project

In a ARC enabled project, is there a way to add the -fno-objc-arc tag programatically in the code it self.
So i could give my source files to someone else, and that person need not add the -fno-objc-arc manually.
I assume this is because you want to distribute your project as a re-usable library that can be used in other projects regardless of whether they use ARC?
I don't think you can add the flag to the source to tell ARC to ignore the file (at least I've not found a way yet), but you can detect if ARC is enabled within the file using
#if __has_feature(objc_arc)
...
#endif
You could use this to raise a warning, by saying
#warning This file is not ARC compatible, add the -fno-objc-arc tag
But an even more elegant solution is to use this feature to automatically branch your code at compile time so that it works on both ARC and non-ARC builds.
I wrote a simple re-usable header that can be pasted into the top of your source file or included in the project as a standalone header file:
https://gist.github.com/1563325
This provides a bunch of macros to use instead of retain, release and autorelease methods so that they can be automatically stripped for ARC builds. For an example of how this is used, check out iRate:
https://github.com/nicklockwood/iRate/tree/master/iRate
It only takes a few minutes to convert a class file this way.
No - not in the code itself. This is stored in your project file, so if you send the entire project to someone else it should work. However, you can't just send them a few classes and have that work (it needs to be the entire project).

Does Xcode Always Compile from Scratch

I sometimes see that change I made shows up on third or 4th build run. It's as if xcode "cache" old compilation.
How to delete all compiled file and start from scratch
One thing that's particularly frustating is this:
I got a compile warning
for this code:
[self.currentBusiness addCategoriesObject:self.currentCategory];
I know what the problem. The automatically generated core data code do not have
- (void)addDistrictsObject:(District *)value;
- (void)addCategoriesObject:(Category *)value;
on Business.h. The function is defined in Business.m though.
So I added those 2 lines. Guess what, still the same warning. I had this exact same problem several time with no issue. I know the solution. I put the line right there in business.h. Nothing changes.
Yet now I get the same compiler warning even though the method is CLEARLY defined in business.h.
As if xcode do not care about the last change I put.
I am so frustated. I added #import "Business.h" again in my utilities.h. Shouldn't change anything given that "Business.h" is already included through other channel. Guess what, it works.
But then I thought, ah that's the problem. I curiously remove that //#import "Business.h" again so it's back like usual. If that's really the issue then the error should show up again right? Wrong.
The error is gone.
So changes I made do not show results right away. Either the compiler or the precompiler must use some sort of cache.
This is important. There are bugs that are introduced 2-3 builds before that I don't know how to debug. If code changes right after the first build after I make that change I know that something is wrong.
Also that autorestore doesn't seem to work. I create a snapshot, restore the snapshot into another directory and get lots of compile error.
NO, It only compile the file in which any kind of any editing took place.
Xcode does incremental builds. You can do a clean build by going to the Product menu item and select Clean (or press Shift+Cmd+K). That will delete all intermediate files and start from scratch.
Click xcode -> Empty Caches.
Here is a screenshot.