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.
Related
This question already has an answer here:
Force Header Files to Compile as C++ in Xcode
(1 answer)
Closed 2 years ago.
I'm trying to use a 3rd party sample code as part of my Objective-C application.
However, when trying to compile my project I get a lot of compiler errors.
The objc syntax that is used in the sample is quite strange and I believe that it is compiled as something else within the project.
For example, as part of the header file the struct definition has default values:
File.h
struct Options
{
int count = 100;
}
...
In their project, the above header file would compile just fine, but when I try to compile it I see an Xcode error:
Expected ';' at end of declaration list
I'm not an objective-c expert, but from what I've read and also found as part of other posts data types cannot have default values, but somehow it compiles fine in the Xcode sample app.
Please let me know if you need more info or other examples of what would compile fine in their project and doesn't work when I copy and paste the code into mine.
Edit:
Force Header Files to Compile as C++ in Xcode
Individually header files doesn't compiled. Compiled source files where they included. If you include them in .c they will be compiled like C, if in .m - like Objective-c, if in .cpp - like C++, if in .mm - like Objective-C++.
My issue was that I was using this header file into a .m file which compiles it to an Objective-C standard. When I change the extension to .mm everything worked fine.
When you think of objective-C as actually being C its more clear why defaults are not set in .h files
This does not apply to the rules of default sizes which are needed when no flexible memory allocation for a data type is available by default, like for (as is) most data types in C.
Even this two sentences already show the difficulty to distinguish what is meant with "default".
Which is why you end up with definition of initiation processes and functions to declare what exactly is "default" in the other file.
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
int count;
} Options;
typedef struct {
int foo;
Options bar[100];
} Foo;
struct Bar {
Foo lotsof;
}
void MyInitiationFunction(Bar *b);
// definition of MyInitiationFunction in .m/.c file
#ifdef __cplusplus
}
#endif
but there is the concept of enum that can trick your mind where defined enumeration default states are what you build some stuff on, which is not a value.
I have done this before, normally without trouble, setting the bridging header, etc.
This time, I tried to import a Obj-C framwork (github.com/jensmeder/FSKModem/) into my swift project. When typing code I can "see" all the Obj-C methods.
But when I compile the code, I get errors like "Use of undeclared identifier 'delete'" or "Use of undeclared identifier 'new'". Example of code in a .m file that is giving the error:
_audioFormat = new AudioStreamBasicDescription();
I'm familiar with Swift and don't know about Obj-C but I guess "delete" or "new" should exist, right? Do they belong to some framework that I should add?
I can compile the original code in Obj-C without trouble, but I need to incorporate it in my project that is written in Swift.
Many thanks for any help
Some more information...
The following functions are inside the .m file. Do you know why the "new" and "delete" keywords are unrecognized? This works fine when compiled as a normal "Obj-C" project. The error appears in Swift project only (after bridging headers of course):
-(void)dealloc
{
[self disconnect:NULL];
if (_audioFormat)
{
delete _audioFormat;
}
}
-(void) setupAudioFormat
{
_audioFormat = new AudioStreamBasicDescription();
//...
}
Should I add some #include that I might be missing, besides Foundation?
new and delete are C++ keywords; you can use them in C++ files (usually .cpp or .cc) and in Objective-C++ files (always .mm). You cannot use them in Swift (.swift) or in Objective-C (.m) files.
It is perfectly valid to use an Objective-C class from an Objective-C++ file from Swift; you can use Objective-C to wrap C++ classes for Swift usage. However it is not valid to use C++ from plain Objective-C.
Quite probably you just need to rename your Objective-C file to .mm.
new and delete are keywords from C++ not from Swift or Objective-C.
Swift
let audioFormat = AudioStreamBasicDescription()
Objective-C
AudioStreamBasicDescription* audioFormat = [[AudioStreamBasicDescription alloc] init];
In Swift, you simply need to call the object initializer when creating an object.
_audioFormat = AudioStreamBasicDescription()
The new keyword is an Objective-C combo of alloc and init.
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?
So this actually makes sense to me, but what I find weird is that this "problem" built without issue for a long time until I went to modify a file.
I have a ViewController class that defines a constant variable lineWidth as
const int lineWidth = 2;
In another class, called GridView, I define the same constant
const int lineWidth = 2;
These are both in the .m files of either class. ViewController.h does import GridView.h.
This caused no issue at all until today when I went to make a modification to GridView.m. The modification had nothing to do with this constant variable; I was merely adding another constructor to the class. When I built the project, I got this error:
Apple Mach-O Linker error: duplicate symbol '_lineWidth' in ViewController.o and GridView.o
I had never seen this error before.
After some trial and error, I was able to get the project to build after changing one of them to nLineWidth. Now I think I figured out that the problem was that I was importing GridView.h from ViewController.h, which then imported ViewController.m and GridView.m, both of which had this constant variable defined, causing an error.
My Question,
however, is why did this build properly up until this point. Is this a new flag that was introduced in XCode 5.1.1? I find it interesting that this wasn't an issue until I started modifying that file. When it needed to rebuild that file, the problem showed up.
Change them both to be:
static const int lineWidth = 2;
This will make each one specific to the file it is defined in. Each can have its own value without affect the other one. Without static they are both declared as app globals and having two with the same name doesn't work.
If you want one shared global then add the following to a .h file:
extern const int lineWidth;
Then add the following to one (corresponding) .m file:
const int lineWidth = 2;
This will create a single global that can be used anywhere by importing the .h file.
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