Objective- C - duplicate interface definition for class - ios

When I build my app in Xcode, I have this error:
Duplicate interface definition for class BFTask
I followed some tutorials and answers, on this site, about headers and I modified it, but nothing has changed. The same error persist during build.
in BFtask.h file:
#import<foundation/Foundation.h>
#class BFTask;
.
.
.
#interface BFTask:NSObject
...
in BFTaskCompletionSource.h file:
#class BFTask;
#interface BFTaskCompletionSource;
in BFTaskCompletionSource.m file:
#import<foundation/Foundation.h>
#import "BFTask.h"
#interface BFTaskCompletionSource()
...
#interface BFTask(BFTaskCompletionSource)

You haven't shown us the BFTask.m file. I suspect you will find you have an #interface BFTask at the top of that file. If you want to declare any additions to a class in the .m file, you have to have an #interface BFTask () with the parentheses...
I have tested this and if you leave out the parentheses, the specific wording you will get for the error is, "Duplicate interface definition for class 'BFTask'"... exactly as you have reported.
If this is correct, you have two possible ways to fix this in the BFTask.m file:
If there is nothing between the #interface BFTask and the following #end, just delete them both.
If there are additional methods or properties declared there, just add a pair of parentheses after the BFTask to have #interface BFTask ().

Related

Cannot find protocol declarations in project-swift.h

I am trying to build my project but am getting these errors:
Cannot find protocol declaration for 'CBCentralManagerDelegate'; did you mean 'CLLocationManagerDelegate'?```
Cannot find protocol declaration for 'CBPeripheralDelegate'```
on this code in my Project-Swift.h file
#class CBService;
#class CBCharacteristic;
#interface KestrelDeviceConnect (SWIFT_EXTENSION(FieldView)) <CBCentralManagerDelegate, CBPeripheralDelegate>
Anyone know what the issue is and how to solve it?
seems like I needed to enter this line of code in the Project-Bridging-Header.h
#import <CoreBluetooth/CoreBluetooth.h>

Linker "Duplicate Symbol" error due to circular reference

I have two header of a class and it's extension(generated by Xcode for NSManaged object). But I'm getting a linker error and I figured out it was due to a circular reference.
Conversation+CoreDataClass.h
NS_ASSUME_NONNULL_BEGIN
#interface Conversation : NSManagedObject
#end
NS_ASSUME_NONNULL_END
#import "Conversation+CoreDataProperties.h"
Conversation+CoreDataProperties.h
#import "Conversation+CoreDataClass.h"
NS_ASSUME_NONNULL_BEGIN
#interface Conversation (CoreDataProperties)
+ (NSFetchRequest<Conversation *> *)fetchRequest;
#end
NS_ASSUME_NONNULL_END
You can clearly see the circular reference here. I found this question where the problem was to add a #class declaration and remove the header. So I commented out the import statement in the Conversation+CoreDataProperties.h and added #class Conversation;. Now two errors pop up saying it's an undefined class. Have attached the screenshot of the error below. I don't quite understand why this is happening and what I need to do to fix it. Any help is much appreciated. Thanks!
Linker error
duplicate symbol _OBJC_CLASS_$_Conversation in:
/Users/xxx/Library/Developer/Xcode/DerivedData/xxx-gbhivuwptwzhkldfbmjghkokozgn/Build/Intermediates/xxx.build/Debug-iphoneos/xxx.build/Objects-normal/arm64/Conversation+CoreDataClass.o
duplicate symbol _OBJC_METACLASS_$_Conversation in:
/Users/xxx/Library/Developer/Xcode/DerivedData/xxx-gbhivuwptwzhkldfbmjghkokozgn/Build/Intermediates/xxx.build/Debug-iphoneos/xxx.build/Objects-normal/arm64/Conversation+CoreDataClass.o
duplicate symbol _OBJC_CLASS_$_ConversationDate in:
/Users/xxx/Library/Developer/Xcode/DerivedData/xxx-gbhivuwptwzhkldfbmjghkokozgn/Build/Intermediates/xxx.build/Debug-iphoneos/xxx.build/Objects-normal/arm64/ConversationDate+CoreDataClass.o
duplicate symbol _OBJC_METACLASS_$_ConversationDate in:
/Users/xxx/Library/Developer/Xcode/DerivedData/xxx-gbhivuwptwzhkldfbmjghkokozgn/Build/Intermediates/xxx.build/Debug-iphoneos/xxx.build/Objects-normal/arm64/ConversationDate+CoreDataClass.o
ld: 4 duplicate symbols for architecture arm64 clang: error: linker
command failed with exit code 1 (use -v to see invocation)
So I commented out the import statement in the Conversation+CoreDataProperties.h and added #class Conversation;.
You may only do this if you're aren't using any of the Convention class's interface (for instance declaring a property of type Convention. You can't do this if you're extending Convention via a category or class extension.
You have a legit circular reference here you must resolve. You can either:
Move the class and the category into the same source file (if there's no special reason this needs to be in a category you could just move the declaration of fetchRequest into the class itself).
Stop importing +CoreDataProperties.h in the class header, and import it instead wherever callers need to be calling fetchRequest.
the duplicate symbols warning do result because
You have the class multiple times in your project and the compiler does not know, which to choose (then it is mostly a duplicate linking error)
There is something wrong with your ConversationDate+CoreDataClass
Just a question that raised from your source code: why do you import an extension of the class you want to extend?
#import "Conversation+CoreDataClass.h"
#interface Conversation (CoreDataProperties)
+ (NSFetchRequest<Conversation *> *)fetchRequest;
#end
All the extension class usually needs to know are basically the classes they extend:
#import "Conversation.h"
#interface Conversation (CoreDataProperties)
+ (NSFetchRequest<Conversation *> *)fetchRequest;
#end
Only the implementation file (.m) would have to import the header file. E.g:
#import "Conversation+CoreDataClass.h"
#implementation Conversation (CoreDataProperties)
+ (NSFetchRequest<Conversation *> *)fetchRequest {
// body
return nil;
}
#end
And last question: Are you sure there exists no other class extension with the same name in your project? CoreData might also have created them itself.
Please have a look in your xCode Project like this:
Found the solution to my problem in this answer. I just had to remove the .m files from the Compile Sources.

error in ACAccount.h in Simulator-iOS 7.1

I'm trying to build and test an app with the xcode simulator, but during the building I get errors in ACAccount.h, ACAccountType.h, etc.
The "strange thing" (at least for me as i'm completely new in using xcode) is that if I click on the .h files with errors they do not appear under the project code but under
Simulator - iOS 7.1-> Frameworks -> Accounts -> ACAccount.h
which is unmodifiable.
Examples of the errors are:
line:
#class ACAccountType,ACAccount Credential; --> Illegal interface qualifier
ACCOUNTS_CLASS_AVAILABLE(NA, 5_0)
#interface ACAccount : NSObject -->Objective-C declarations may only appear in global scope
If the .h are predefined files.. How can I solve these errors?
Many thanks in advance!
Generally when you encounter items like the 'illegal interface qualifier' in system provided headers it indicates that you've placed the #import statement within an #interface block, like:
#interface foo ()
#import <Accounts/ACAccount.h>
#end
This generates errors about the content in the file being imported (e.g. your illegal interface qualifier error), while the actual issue is that putting #import statements within an #interface block is invalid.
You should put #import statements together at the top of the file, outside of any #interface or #implementation blocks.
If you put it into the #implementation section, the error becomes:
error: Objective-C declarations may only appear in global scope

Multiple ViewController inheritance causes Apple Mach-O Linker Error

I'm setting up a base view controller called "BHAccountBaseViewController" and two other views that inherit from some basic functionality from the base controller.
"BHAccountBaseViewController" Inherits from "UIViewController"
"BHAccountViewController" (implements UITextFieldDelegate) and Inherits from "BHAccountBaseViewController"
Lastly I have one recently created class that I called "BHCreateProfileViewController" every time that I just simply include #import directive to "BHAccountBaseViewController" to inherit from this class Xcode fails to compile due to APPLE MACH-O LINKER ERROR!
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Thoughts? these are my three header files
BHAccountBaseViewController
#import <UIKit/UIKit.h>
#import "BHFileManager.h"
#interface BHAccountBaseViewController : UIViewController
#end
BHAccountViewController
#import "BHAccountBaseViewController.h"
#interface BHAccountViewController : BHAccountBaseViewController<UITextFieldDelegate>
#end
BHCreateProfileViewController
#import "BHAccountBaseViewController.m"
#interface BHCreateProfileViewController : UIViewController <UITextFieldDelegate>
#property (strong, nonatomic) id user;
#end
if I comment out the import on the last file the linker error goes a way! but I want to be able to inherit from my base clase ... thoughts?
Help would be much appreciated!
In implementation of BHCreateProfileViewController given above, I found the code looks like getting wrong at first line. What about fixing it as following:
#import "BHAccountBaseViewController.m"
to
#import "BHAccountBaseViewController.h"
and I wonder why BHCreateProfileViewController comes to inherit from UIViewController not BHAccountBaseViewController. Could you explain that?
This might be due to the retain cycle deadlock problem. You have to use forward class declaration for this i.e you can try #Class instead of #import. Please refer to these limks :
Objective-C: Forward Class Declaration
#class vs. #import
These might help.
In the compilation time your compiler would actually look for your interface files instead of implementation file.Compiler does not bother even if .m file is not available. So while importing you are supposed to import .h instead .m.

Unknown type name when trying to include a library

I'm trying to use Novocaine in an iPhone application I'm building. I can't figure out how to get around this error I'm getting:
Unknown type name 'RingBuffer'
Here's my file structure:
...with those files under Novocaine being the ones pulled from the Github repo for Novocaine. Here's my header file for DDViewController.
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#import "UICoordButton.h"
#import "Novocaine.h"
#import "RingBuffer.h"
#import "AudioFileReader.h"
#import "AudioFileWriter.h"
#interface DDViewController : UIViewController
{
RingBuffer *ringBuffer;
Novocaine *audioManager;
AudioFileReader *fileReader;
AudioFileWriter *fileWriter;
}
- (IBAction)changeColor:(id)sender;
- (IBAction)changeColor2:(id)sender;
#end
I've tried a solution that I found on another question, which suggests that this should work:
#class RingBuffer;
#interface DDViewController : UIViewController
{
...
But that just gives me Redefinition of 'RingBuffer' as a different kind of symbol.
How can I fix this problem and use RingBuffer?
RingBuffer is a C++ class. I recommend you change the extension of your Objective-C files from .m to .mm which will make them Objective-C++
Found the answer (or I guess a combination of answers):
Follow coryalder's advice for setting the compiler default to Objective-C++ as described here.
Also, change all .m files to .mm files, and finally add -fno-objc-arc compiler flags to all the .mm files -- which is described in detail here.

Resources