Cannot find protocol declarations in project-swift.h - ios

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>

Related

Objective- C - duplicate interface definition for class

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 ().

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.

Unknown Type even though Im importing

I'm getting this error,
Unknown type name ArrowWrapper
from within BoxSprite.h
#import <Foundation/Foundation.h>
#import "cocos2d.h"
#import "BoxSum.h"
#import "ArrowWrapper.h"
#interface BoxSprite : CCSprite {
}
#property ArrowWrapper* arrowItem;
#end
Also, ArrowWrapper.h contains this.
#import "cocos2d.h"
#import "BoxSprite.h"
#interface ArrowWrapper : CCMenuItem {
}
#property BoxSprite* box;
#end
The error used to be in ArrowWrapper saying it couldnt find BoxSprite until I did a clean, and now it's in BoxSprite saying it can't find ArrowWrapper.
I can't figure out what I'm missing.
Thanks in advance for any help.
You have a recursive import: "BoxSprite.h" imports "ArrowWrapper.h" and vice versa.
You have to remove one of the import statements and use #class instead. For example in "BoxSprite.h" replace
#import "ArrowWrapper.h"
by
#class ArrowWrapper;
You can then import "ArrowWrapper.h" in the implementation file "BoxSprite.m", if necessary.
Detailed explanation: Xcode displays the error in "BoxSprite.h", but the error actually occurs when "ArrowWrapper.m" is compiled:
"ArrowWrapper.m" imports "ArrowWrapper.h".
"ArrowWrapper.h" imports "BoxSprite.h" before defining the ArrowWrapper class.
"BoxSprite.h" imports "ArrowWrapper.h": But "ArrowWrapper.h" is already marked as imported, so the compiler does not read it again.
Therefore, when reading "BoxSprite.h", the ArrowWrapper class has not been defined yet, causing the compiler error.
Replacing import by #class solves the problem, because it makes the ArrowWrapper class known to the compiler at that point without reading the interface file.
I think the issue is with import statements.
You are importing #import "ArrowWrapper.h" in BoxSprite.h and importing #import "BoxSprite.h" in ArrowWrapper.h
So Change the BoxSprite.h like :
#import <Foundation/Foundation.h>
#import "cocos2d.h"
#import "BoxSum.h"
#class ArrowWrapper;
#interface BoxSprite : CCSprite {
}
#property ArrowWrapper* arrowItem;
#end

Cannot find protocol declaration for NSFetchedResultsController

Something weird happened to my app. All was working the other night but now when I load in xcode i get 'Cannot find protocol declaration for NSFetchedResultsController' error in my application.h file for the NSFetchedResultsControllerDelegate
#import <CoreData/CoreData.h>
#import <UIKit/UIKit.h>
#import <StoreKit/StoreKit.h>
#import <MessageUI/MFMailComposeViewController.h>
#class DBRestClient; #interface DartScorerAppDelegate: NSObject <NSFetchedResultsControllerDelegate, MFMailComposeViewControllerDelegate, UIActionSheetDelegate, UIAlertViewDelegate, UIApplicationDelegate> {
I haven't changed anything in this code. I've tried cleaning, unlinking the framework and reimporting, taking out the references to all the code files and reimporting them, but nothing clears this error message. It's affecting all instances of the NSFetchedResultsController and I'm out of ideas on how to resolve it. Can anyone help?
I just encountered this. My issue was that I simply forgot to import <CoreData/CoreData.h>. In your case, maybe it's a bug? Try deleting that line and reimporting it relying on the autofill.

Resources