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:
Related
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.
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"
I'm using the Accessorizer code helper for xCode. I seem to have it configured correctly and it is generating property statements and synthesize statements fine.
It is not generating the release statements however when I choose the dealloc action.
If I choose dealloc against an NSTimer, it does generate the [myTimer invalidate] statement, but not the release statements, so it seems to be triggering the dealloc action, but the action isn't configured properly? and so no release code generated.
Has anyone come across an issue like this using accessorizer?
Amazing how you find an answer just after asking a question.
For anyone else that has this issue, turn off ARC Aware in the Accessor Style TAB of the Accessorizer application. (yes seems bleedingly obvious in hindsight, was stupidly thinking it might be aware of the xcode project settings and ARC isn't on for this project, but its really just a 'dumb' editing tool that operates only on the input text i.e. not integrated to xCode).
The things we have to go through to do something that anyone who codes objective C for more than half an hour would have made the first feature of a new IDE. (automatic generation of property/synthesize etc.)
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.
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).