add your classes to stop arc mode
Reachability class ARC error in iOS
-
03-10-2022 - |
Question
Hi. I imported reachability.h file and reachability.m file in order to check the internet connection in my application but I'm getting an ARC error.
I have to tried to convert application into ARC but it's still showing the same error as follows:
compile Reachability.m and compile Reachability m files
implicit conversion of objective c pointer type 'Reachability *' to Cpointer type void * requires a bridged cast
ARC forbids explicit message send of 'dealloc'
ARC forbids explicit message send of 'autorelease'
ARC forbids explicit message send of 'autorelease'
'NSAutoreleasePool' is unavailable: not available in automatic reference counting mode
'NSAutoreleasePool' is unavailable: not available in automatic reference counting mode
Cast of C pointer type 'void*' to Objective - C pointer type 'Rachability*' requires a bridged cast
release is unavailable: not available in automatic reference counting mode
ARC forbids explicit message send of 'release
I don't know how to solve this problem. Please I need help.
Thanks
Solution
OTHER TIPS
Depending on whether you want to use the class as-is you can always enable ARC for just a single file, not the complete project.
Pretty handy for including third-party sources that either require or don't ARC.
I think you are using an older version of the code. Refer to the Apple sample code for Reachability which is updated to use ARC.
Hope that helps!
I would recommend you to read Apple documentation about the transition to ARC: Transition to ARC.
As you will learn ARC automatically dealloc objects in memory based on how many strong pointer are currently pointing to a specific object. When no strong pointers (zero) to an objects are left ARC will dealloc that object immediately. Therefore you won't use autorelease anymore as all the objects are autoreleased with ARC.
You can call dealloc (although I wouldn't do it except if strictly necessary) to run some come prior the object to be dealloc'd by ARC. It's very important however that in the dealloc method you don't call the super class method (which I assume is the causes of the errors associated to dealloc) as this will be completely handled by ARC. I hope this helps.
Add the -fno-objc-arc
flag to any files for which you'd like to enable ARC, as described in the ARC documentation.
Reachability file you are using is older version. You can download latest version of Reachability file compatible with iOS 6.0 and later.
For older version of Reachability files you can add some flags to enable ARC
- Open Targets of your project
- Select Build Phases
- Open Compile Sources tab
- Double click next to Reachability file
- Add
-fno-objc-arc
flag