Strange issue 'Cannot find type 'RCTResponseSenderBlock' in scope' on Swift module React Native - objective-c

I have a very strange problem: "Can't find the type RCTResponseSenderBlock in scope." It's strange, because in one case it is there and in the other it doesn't, looks like a bug.
This is screenshot issue.
This my Objective-C file:
#import <Foundation/Foundation.h>
#import "React/RCTBridgeModule.h"
#import <React/RCTEventEmitter.h>
#import <React/RCTConvert.h>
#interface RCT_EXTERN_MODULE(BLEclass, NSObject)
RCT_EXTERN_METHOD(addEvent:(NSString *)name callback:(RCTResponseSenderBlock)callback )
#end
And this my Swift file, where i have issue :
import Foundation
#objc(BLEclass)
class BLEclass: NSObject{
#objc(addEvent:callback:)
func addEvent(_ name: String,_ callback:RCTResponseSenderBlock){
NSLog("%#", name);
let resultsDict = [
"name" : name
];
callback([NSNull(),resultsDict])
}
}
If you know how to fix it, please write answer.
Thanks.

I had this same issue and discovered I had to add the import to my main bridge file.
#import <React/RCTBridgeModule.h>
#import <React/RCTViewManager.h>
I out which file was set by looking at the Build settings under Swift Compiler - General -> Objective-C Bridging Header which appears to be the default for the app.

Related

Cannot find interface declaration in myproject-swift.h

I'
m using XLPagerTabStrip pod in my project,
i have a bridging header for other purposes to integrate from swift to objective c myproject-swift.h
i cant build the project and this error always pops:
Cannot find interface declaration for
'ButtonBarPagerTabStripViewController', superclass of
'ParentViewController'
This is my Controller
import Foundation
import UIKit
import XLPagerTabStrip
class ParentViewController: ButtonBarPagerTabStripViewController {
override func viewDidLoad() {
tabStripStyle()
super.viewDidLoad()
containerView.isScrollEnabled = false
}
}
I have seen this issue everywhere posted but its not yet answered here: 'Cannot find interface declaration' in auto-generated Swift bridging header
Bugs in swift SR-805 SR-5398
You needed to import the -Swift.h for for both the framework and the app target
For Example :
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#import <Foundation/Foundation.h>
#import "XLPagerTabStrip-Swift.h"
#import "RealmSwift-Swift.h"
...... // Add all frameworks, subclasses, and dependance ios frameworks
#import "MyProject-Swift.h"
You can read this article How to import file header and check paths
I had error "Cannot find interface declaration for 'CLLocation', superclass of 'MYLocation'
for below code
#interface MYLocation : CLLocation // code in MyProject-Swift.h
when I just imported
#import <MyProject/MyProject-Swift.h>
after importing below both, the error is gone.
#import <CoreLocation/CoreLocation.h>
#import <MyProject/MyProject-Swift.h>

Combinating Swift & Objective C files

I have a bit complicated classes in swift and Objective-C combinated together:
Keypad.h:
#import "MyApp-Swift.h"
#interface Keypad : UIViewController {
...
SwiftViewController *swiftViewController; // this is written in swift
...
}
This worked well.
Then I created a new swift file:
AnotherSwiftViewController.swift
#objc class AnotherSwiftViewController: UITableViewController {
func myMethod() {
let keypad = appDelegate.getTabs().selectedViewController as! Keypad // I need get ObjC Keypad class
}
}
And I need to use there the ObjcC Keypad class.
So I added it to the MyApp-Bridging-Header.h:
MyApp-Bridging-Header.h
...
// lot of other Obj-C files imported
...
#import "Keypad.h"
...
And I get the error:
> .../MyApp-Bridging-Header.h:31:9: note: in file included from .../MyApp-Bridging-Header.h:31: #import "Keypad.h"
> .../Keypad.h:13:9: error: 'My_App-Swift.h' file not found \#import "My_App-Swift.h"
> <unknown>:0: error: failed to import bridging header '.../MyApp-Bridging-Header.h'
Any ideas?
/// EDIT:
Maybe will help:
I'm using
#import "My_App-Swift.h"
In the Keypad.h file, not in standard Keypad.m, because I have there that SwiftViewController *swiftViewController; property
Maybe it will help
You have a good point in your ///Edit.
In Keypad.h remove #import "MyApp-Swift.h" and add a forward declaration of your Swift class as follows:
...
#class SwiftViewController;
#interface Keypad : UIViewController {
...
This should do it assuming Keytab.h references SwiftViewController only by pointer and your bridging header is imported correctly otherwise.
See section Referencing a Swift Class or Protocol in an Objective-C Header in https://developer.apple.com/library/content/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html.

How to make protocol from Swift visible in .h file?

I have a 3 files:
PLThreadViewController.swift
#objc protocol PLThreadViewDelegate {
func threadViewControlledWillDismiss(threadViewController: PLThreadViewController)
}
class PLThreadViewController: UIViewController {}
PLMessagesTableViewController.h
#import <UIKit/UIKit.h>
#interface PLMessagesTableViewController : UITableViewController <PLThreadViewDelegate>
#end
The problem is: Cannot find the protocol declaration for PLThreadViewDelegate
When i try to add:
#import "Module-Swift.h"
then:
Module-Swift.h file not found. The name of module is very correct. I read about spaces, underscores in the name and so on.
Did Xcode create a bridging header for you? If so, look at the naming Xcode uses there and that will clue you in on how your "-Swift.h" file is named. So if your bridging header is named My_Project-Bridging-Header.h, your auto-generated Swift header will be My_Project-Swift.h.

iOS: What can cause the Xcode compiler to throw errors when I include my AppDelegate.h into another header file?

I am trying to #import my "AppDelegate.h" into another header file of the same project in order to access methods of the AppDelegate of my iOS project.
So, my header file looks something like this:
#import
#import "DataProvider.h"
#import "MyAppDelegate.h"
#interface MyViewController : UIViewController <UITextFieldDelegate, UIAlertViewDelegate> {
...
}
and I want to use my AppDelegate like this:
MyAppDelegate* appDelegate = (MyAppDelegate*)[UIApplication sharedApplication].delegate;
[appDelegate doSomething];
However, as soon as I #import "MyAppDelegate.h", the compiler throws a lot of (unrelated) errors, like
Cannot find interface declaration for 'MyOtherViewController', superclass of 'MyOtherViewController2'
The thing is: I can include my AppDelegate just fine in other headers. And I cannot figure out what the difference might be. Please help me figure out what could cause this! Thanks a lot!
PS: This happens with GCC as well as the new LLVM.
Move the #import into the .m file. If you need the MyAppDelegate symbol in your .h, use #class MyAppDelegate; instead.

Objective-C not recognizing .h?

I have the following in a project named testApp: (testAppViewController is the valid name of my view controller in the project)
PrevView.h
#import <UIKit/UIKit.h>
#import "testAppViewController.h"
#interface PrevView : UIView {
testAppViewController *viewController;
}
#property (nonatomic,retain) testAppViewController *viewController;
#end
When I build the project I'm getting the following error:
PrevView.h:13: error: expected specifier-qualifier-list before 'testAppViewController'
Am I missing something here? Any ideas?
Does "testAppViewController.h" import "PrevView.h"?
If so, you may want to delcare a forward class reference:
#class testAppViewController;
that replaces the import you have, and move the import into the .m file.
Usually when I see this type of error, it's a problem in the header file that you're trying to import. Check "testAppViewController.h"