Converting to ARC doesn't recognize -fno-objc-arc flag - ios

I am finally trying to convert my ios project to ARC. there is several files that I do not want to convert to ARC, so I have added the "-fno-objc-arc" flag to build phase -> compile sources to the corresponding *.m file.
However, when I try to edit -> refactor -> convert to ARC, I am getting a "Cannot Convert to Objective-C ARC: Xcode found 3 issues that prevent conversion from proceeding. Fix all ARC readiness issues and try again." error
the errors are all on the *.h file for which I have added the -fno-objc-arc to for the corresponding *.m file... Do I have to add the flag to the *.h file too? If so, where can I find it?
Thanks!
EDIT So I read the error more clearly. the file i am having issue with is JSONKit.h. The errors are not generated in JSONKit.m, but other classes that I wrote which imports JSONKit.h So is the only solution to add the -fno-objc-arc flag to my own classes that imports JSONKit.h? Thanks

temporary getaround (unless someone can suggest better)
I have having error with the following in JSONKit.h
typedef struct {
JKParseOptionFlags parseOptionFlags;
JKConstBuffer stringBuffer;
size_t atIndex, lineNumber, lineStartIndex;
size_t prev_atIndex, prev_lineNumber, prev_lineStartIndex;
int errorIsPrev;
JKParseToken token;
JKObjectStack objectStack;
JKTokenCache cache;
JKObjCImpCache objCImpCache;
NSError *error;
} JKParseState;
the error is on the NSError line - "ARC forbids Objective-C objects in structs or unions"
following another stackoverflow question, I changed the line to
__unsafe_unretained NSError *error;
and it compiles... seems to work ok so far

Related

typedef redefination issue in iOS project

I am using a third party library (https://github.com/zhang28602/ZZYQRCode) for my project. When I indergrated it into my project it started throwing the following error: Typedef redefinition with different types ('void (^)(NSString *__strong)' vs 'void (^)(__strong id, NSURLResponse *__strong)')
for the following line of code: typedef void(^SuccessBlock)(NSString *reuslt);
Please help me resolve this.
That project has defined a global typedef in its public header using a very generic name (SuccessBlock). You likely have defined SuccessBlock in another way somewhere else in your program.
If possible, have the developer use prefixes on their names. This should have been ZZYSuccessBlock. Alternately, rename the other instance of SuccessBlock.
If that's not possible, try to ensure that no part of your system imports both ZZYQRCode.h and whatever .h file defines the other version of it.

Duplicate symbol error with GoogleCast.framework

I just started porting an Android app to iOS, and am hitting a major roadblock that I can't figure out despite scouring many similar questions.
I am attempting to follow the pattern implemented in the CastVideos sample where the GoogleCast API is encapsulated in a singleton class which I've called CastManager. To use my singleton class, I #import "CastManager.h" in AppDelegate.m. Then in CastManager.h, I #import <GoogleCast/GoogleCast.h> so that I can use classes and protocols from it as part of CastManager's public interface. However, because I'm importing CastManager.h in both CastManager.m and AppDelegate.m, the linker is finding duplicate symbols from the GoogleCast framework.
This is my CastManager.h:
#import <GoogleCast/GoogleCast.h>
#import <Foundation/Foundation.h>
#interface CastManager : NSObject
#property(nonatomic, strong) GCKDeviceScanner *deviceScanner;
+ (instancetype)sharedCastManager;
#end
And corresponding CastManager.m:
#import "CastManager.h"
#implementation CastManager
+ (instancetype)sharedCastManager {
NSLog(#"sharedCastManager");
static CastManager *singleton = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
singleton = [[self alloc] init];
});
return singleton;
}
- (instancetype)init {
NSLog(#"init()");
if (self = [super init]) {
self.deviceScanner = [[GCKDeviceScanner alloc] init];
}
return self;
}
#end
And this is the main part of my AppDelegate.m:
#import "AppDelegate.h"
#import "CastManager.h"
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
CastManager *castManager = [CastManager sharedCastManager];
return YES;
}
However, this results in the following error from the linker when attempting to build the project:
duplicate symbol _kGCKDeviceCapabilityVideoOut in:
/Users/nate/Library/Developer/Xcode/DerivedData/MyCastApp-ezrgxdnlvywpanerezulnarzknno/Build/Intermediates/MyCastApp.build/Debug-iphonesimulator/MyCastApp.build/Objects-normal/x86_64/AppDelegate.o
/Users/nate/Library/Developer/Xcode/DerivedData/MyCastApp-ezrgxdnlvywpanerezulnarzknno/Build/Intermediates/MyCastApp.build/Debug-iphonesimulator/MyCastApp.build/Objects-normal/x86_64/CastManager.o
... many similar errors ommitted for brevity ...
duplicate symbol _kGCKDeviceCapabilityAudioIn in:
/Users/nate/Library/Developer/Xcode/DerivedData/MyCastApp-ezrgxdnlvywpanerezulnarzknno/Build/Intermediates/MyCastApp.build/Debug-iphonesimulator/MyCastApp.build/Objects-normal/x86_64/AppDelegate.o
/Users/nate/Projects/MyCastApp/GoogleCast.framework/GoogleCast(GCKDevice.o)
ld: 8 duplicate symbols for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
As far as I can tell, this exactly copies the pattern as defined in the CastVideos sample, but the sample compiles fine, and mine doesn't, and I've scoured through both projects trying to find what is different, but I just don't see it. Further, I don't see anything really wrong with doing this, and would expect it to work fine. I can't think of any other way to do it, really.
Here are the relevant files from the CastVideos sample for comparison:
ChromecastDeviceController.h
ChromecastDeviceController.m
AppDelegate.m
Other questions point to solutions that don't apply or don't fix it:
I'm not importing a .m file on accident.
I don't have duplicate references to any files in the project.
The "Compile Sources" section of the "Build Phases" project setting doesn't include any duplicates.
I've added the '-ObjC' linker flag as described by the GoogleCast API docs, though it has the same error with or without it.
I've tried deleting the delegate data and doing a clean before building.
This is with Xcode 6.3.1 running on OS X Yosemite 10.10.3 and the GoogleCastSDK-2.6.0 package from the SDK documentation page
I have checked in my sample project with the problem at https://github.com/nshafer/MyCastApp
Any help is greatly appreciated!
Edit: the duplicate is somewhat related, it's definitely about the same symbols, but the answers there didn't help, as I'm not using Object-C++, but rather just Objective-C. I don't have a .mm file, just a .m file.
For me it helped to switch the "No Common Blocks" compiler setting to NO:
It pretty much seems to make sense, the setting is explained here: What is GCC_NO_COMMON_BLOCKS used for?
The linker tells you that you have a variable named kGCKDeviceCapabilityVideoOut in two files, AppDelegate.m and CastManager.m. Since it's not in your source code, it's most likely in the GoogleCast code that you are including.
Either change the GoogleCast.h file, or make sure it is only included in one .m file. Including it from CastManager.h means it is indirectly included in every file that includes CastManager.h, so I would avoid that and only include it from CastManager.m. You'll probably have to add
#class GCKDeviceScanner;
in your CastManager.h file.
I found another fix, which is to edit GCKDevice.h in the GoogleCast.framework/Headers folder. Change the 4 constants from GCK_EXPORT to GCK_EXTERN near the top of the file.
/** Device capability flag for video out. */
GCK_EXTERN const NSInteger kGCKDeviceCapabilityVideoOut;
/** Device capability flag for video in. */
GCK_EXTERN const NSInteger kGCKDeviceCapabilityVideoIn;
/** Device capability flag for audio out. */
GCK_EXTERN const NSInteger kGCKDeviceCapabilityAudioOut;
/** Device capability flag for audio in. */
GCK_EXTERN const NSInteger kGCKDeviceCapabilityAudioIn;
I detailed this in a bug report I filed with Google's issue tracker, but it was marked as a duplicate of another somewhat related issue. Either way, it will perhaps get fixed in the next version. Until then, I would suggest going with changing the "No Common Blocks" setting as detailed in Joobik'com's answer, as that doesn't involve changing the 3rd party code.

Getting "Expected a type" error in XCode

I'm getting this error:
/Class/GData/OAuth/GDataOAuthViewControllerTouch.m:116:22: Expected a type
That line is:
authentication:(GDataOAuthAuthentication *)auth
Inside of this block of code:
- (id)initWithScope:(NSString *)scope
language:(NSString *)language
requestTokenURL:(NSURL *)requestURL
authorizeTokenURL:(NSURL *)authorizeURL
accessTokenURL:(NSURL *)accessURL
authentication:(GDataOAuthAuthentication *)auth
appServiceName:(NSString *)keychainAppServiceName
delegate:(id)delegate
finishedSelector:(SEL)finishedSelector {
NSString *nibName = [[self class] authNibName];
I'm a newb XCode developer. So far I've created and compiled a calculator app based from an online class but that's it.
Is this a library that is not being included?
Background: The previous developer abandoned the project and the owner sent the project code to me. I'm trying to replace the existing graphics with new graphics and recompile it with support for iOS 6, which I thought I should be able to do without any coding, but have run into this error and many others when I opened the project. I have the latest XCode.
The :22 (and the position of the caret within the editor) tell you exactly where on the line the error is. In this case it's telling you that where it sees GDataOAuthAuthentication it was expecting a type. So, implicitly, it doesn't recognise that GDataOAuthAuthentication is a type.
Objective-C still sits upon compilation units ala C — each .m file is compiled in isolation then the lot are linked together. You use #import (or #include if you want; #import just guarantees the same file won't be included twice) to give each individual file visible sight of any external definitions it needs.
So, that's a long-winded way of reaching the same conclusion as Rick did five minutes ago: you've probably omitted a necessary #import.
A few things to look for:
Did you #import the file where the GDataOAuthAuthentication type is defined? (e.g. #import "GDataOAuthAuthentication.h")
Is there a variable named GDataOAuthAuthentication which is causing the compiler to think GDataOAuthAuthentication is a variable not a type?

Not able to compile Ziparchive library (iOS)

I need to download and unzip a file in my Xcode project,
I am using Ziparchive (https://code.google.com/p/ziparchive/downloads/detail?name=ZipArchive.zip) to do so,instead of following every step I am getting compilation error as below:
/Developer/AR/vuforia-sdk-ios-2-6-8/samples/ARDemo/minizip/ioapi.c:68:18: Redefinition of 'fopen_file_func' as different kind of symbol
/Developer/AR/vuforia-sdk-ios-2-6-8/samples/ARDemo/minizip/ioapi.c:68:35: Use of undeclared identifier 'opaque'
/Developer/AR/vuforia-sdk-ios-2-6-8/samples/ARDemo/minizip/ioapi.c:68:58: Expected ';' after top level declarator
/Developer/AR/vuforia-sdk-ios-2-6-8/samples/ARDemo/minizip/ioapi.c:72:1: Expected unqualified-id
/Developer/AR/vuforia-sdk-ios-2-6-8/samples/ARDemo/minizip/ioapi.c:90:17: Redefinition of 'fread_file_func' as different kind of symbol
Developer/AR/vuforia-sdk-ios-2-6-8/samples/ARDemo/minizip/ioapi.c:90:42: Use of undeclared identifier 'stream'; did you mean 'strcat'?
Developer/AR/vuforia-sdk-ios-2-6-8/samples/ARDemo/minizip/ioapi.c:90:50: Use of undeclared identifier 'buf'
/Developer/AR/vuforia-sdk-ios-2-6-8/samples/ARDemo/minizip/ioapi.c:95:1: Expected unqualified-id
I dont have a clue how to compile it successfully, any help is appreciated.
In my case, it happens because I have an incorrect Prefix file.
It was including objective c imports outside the "#ifdef OBJC" block
So that there was no problem when all classes were objetctive-C classes but it didn't compile when I add the C classes of minizip.
Just moving all the imports in the prefix file inside the obj block and voilà!
#ifdef __OBJC__
#import <Availability.h>
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#endif
I hope this helps
Please Add the FrameWork libz.dylib in your project and solve your problem
Project setting -> Target-> Build Phases -> Linked Frameworks and Libraries -> select ibz.dylib
I got the solution,I am using Metaio SDK for Augmented Reality which has a compile dependancy, it can only be compiled as "Compile sources as - > Objective C++" and this was the reason creating the problem, Ziparchive compiled fine otherwise, now to merge both in the same project I made Ziparchive as a STATIC LIBRARY and linked it in Xcode, it solved the problem.

How to implement the ADLivelyTableView class in a project that uses ARC

I have gone through the ADLivelyTableView demo project but have not been able to import the ADLivelyTableView h and m files into my project successfully. It appears that the main issue is to do with ARC. I have experimented by converting the demo project into arc, specifically but converting just the LDMasterView.m file, and this simply removes all references to releasing objects, and so after this conversion, the use ARC option under build settings is now ON and the app works. So i figured that the ADLivelyTableView .m and .h files dont need converting, but when these are imported into my project, i get all sorts of ARC errors for these two blocks of code:
if (block != _transformBlock) {
Block_release(_transformBlock);
_transformBlock = Block_copy(block);
}
}
and
#implementation ADLivelyTableView
- (void)dealloc {
Block_release(_transformBlock);
[super dealloc];
}
I dont get why these errors didnt show when turning on ARC in the demo project. id prefer finding a solution rather than trying to import my entire application to the demo project instead! The errors are as follows:
ARC Casting Rules: Cast of block pointer type 'ADLivelyTransform (aka NSTimeINterval (^)CALayer*_strong, float) to C pointer type 'const void *' required a bridged cast.
ARC Casting Rules: Cast of C Pointer ....(Same as above)
Also, once this issue is resolved, it is supposed to be as simple as just importing the ADLivelyTableView .h and .m files and then adding the line :
ADLivelyTableView * livelyTableView = (ADLivelyTableView *)self.tableView;
livelyTableView.initialCellTransformBlock = ADLivelyTransformFan;
into my viewDidLoad section? or is that bit supposed to be edited for my specific table?
Thanks for your help,
Regards,
Rami
You can modify the Compiler Flags for ADLivelyTableView.m.
Kindly try to add -fno-objc-arc.

Resources