Do all react-native '.h' modules have to be prepended with 'React/'? - ios

Setup:
react-native v0.41.2
react-native-cli v2.0.1
xcode v8.2.1
node v6.9.5
I started using RN v0.41.2 and found that v0.40 introduced a namespace breaking change stating that all react imports should be prepended with React/.
But the documentation shows otherwise.
So, is doing this the only thing that I have to do:
// RNLib.h
#import "RCTBridgeModule.h"
#interface RNLib : NSObject <RCTBridgeModule>
#end
to
// RNLib.h
#import <React/RCTBridgeModule.h>
#interface RNLib : NSObject <RCTBridgeModule>
#end
Or do I have to do it for my imports as well:
// RNLib.m
#import "RNLib.h"
#implementation RNLib
RCT_EXPORT_MODULE();
RCT_EXPORT_METHOD(helloWorld:(NSString *)world)
{
return [NSString stringWithFormat:#"hello %#", world];
}
#end
to
// RNLib.m
#import <React/RNLib.h>
#implementation RNLib
RCT_EXPORT_MODULE();
RCT_EXPORT_METHOD(helloWorld:(NSString *)world)
{
return [NSString stringWithFormat:#"hello %#", world];
}
#end
I'm currently unable to create a library and link it correctly (I've tried multiple things).

// somthing.m
#import "something.h"
This above line refers to something.h file which is present in same directory of the implementation file.
Only Modules from the React should be prepended with "React/RCTWhatever.h".
This has effective change in Header Search Paths of Xcode when you are linking the Native Libraries.
Thanks

Related

React Native - ios Native Module not working

I'm following the example posted in the official doc for native module ios. I've set up everything, build it and run the application.
// CAL.h
#import <React/RCTBridgeModule.h>
#interface CAL : NSObject <RCTBridgeModule>
#end
// CAL.m
#import <React/RCTLog.h>
#import "CAL.h"
#implementation CAL
RCT_EXPORT_MODULE(CAL);
RCT_EXPORT_METHOD(createCalendarEvent:(NSString *)name location:(NSString *)location)
{
RCTLogInfo(#"Pretending to create an event %# at %#", name, location);
}
#end
But when I check NativeModules from react-native it shows an empty object - {}.
I'm not sure what I'm missing.
Like #chengsam mentioned, when I access CAL directly in the following manner it works.
const { CAL } = NativeModules;
or
NativeModules.CAL
CAL still held the native module while NativeModules directly displayed {}

Why do I get Method definition for ... not found error after refactoring?

I have a very small class with an enum in the .h file, and that's it. I recently refactored the name of the .h file and for some reason the .m file names didn't refactor, so I had to change it manually. Now everything works as intended, but I suddenly get a warning on my #implementation in my .m file: Method definition for ... not found. Not sure why.
It looks like this in .m:
#import "TabTypeEnum.h"
#interface TabTypeEnum ()
#end
#implementation TabTypeEnum
- (void)viewDidLoad {
[super viewDidLoad];
}
#end
and in the .h
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
#interface TabTypeEnum : UIViewController
typedef enum {
MyTravels = 0,
Excursions,
Experiences,
Map,
Discover
} MyTabType;
- (void)myTabFunc: (MyTabType) myTab;
#end
NS_ASSUME_NONNULL_END
I didn't get the warning before, and all I did was change all the names to TabTypeEnum. I don't want to have the method implemented in the .m file. It's fine as it is.

React-Native: Error trying to get in touch with native module in the tutorial

Having issue with defining a native module from the tutorial in https://facebook.github.io/react-native/docs/native-modules-ios.html.
#import "CalendarManager.h"
#import <React/RCTLog.h>
#implementation CalendarManager
RCT_EXPORT_MODULE();
RCT_EXPORT_METHOD(addEvent: (NSString *)name location: (NSString *)location)
{
}
#end
It give me the compile error in RCT_EXPORT_METHOD saying
"Expected ')'"
.
and
'Type specifier missing, defaults to int' (later also appeared under
RCT_EXPORT_MODULE)
You need to insert #import <React/RCTBridgeModule.h> in CalendarManager.h either.
Like this
#import <Foundation/Foundation.h>
#import <React/RCTBridgeModule.h>
NS_ASSUME_NONNULL_BEGIN
#interface CalendarManager : NSObject<RCTBridgeModule>
#end
NS_ASSUME_NONNULL_END

Parse Issue in Xcode 4.6.3 - "Expected a type" - Can't find the error

I have a Problem with Xcode:
At the moment I am working on an application for iOS SDK 6.1. Somedays ago I was implementing some methods and tried to compile the project.
Then something strange happened:
Compilation failed and I got some errors (see picture below) in two files, which aren't related to the methods I worked on.
I searched for errors in my code but couldn't find any.
Then I closed the project and opened it again: They were still here.
Then I closed the project and Xcode and reopened both: They were still here.
Then I created a new project and copied all the code: The issue appeared again.
Now I am stuck and have no clue what to do. Do I miss something in my code?
Please help me!
---
EDIT 1:
Here are some code snippets, which should show my code after I followed the suggestions of Martin R:
// PlayingCardDeck.h
#class PlayingCard;
#interface PlayingCardDeck : NSObject
- (void) addCard: (PlayingCard *) card atTop: (BOOL) atTop;
- (PlayingCard *) drawRandomCard;
- (BOOL) containsCard: (PlayingCard *) card;
- (BOOL) isCardUsed: (PlayingCard *) card;
- (void) drawSpecificCard: (PlayingCard *) card;
- (void) reset;
#end
// PlayingCardDeck.m
#import "PlayingCardDeck.h"
#interface PlayingCardDeck()
// PlayingCard.h
#import <Foundation/Foundation.h>
#import "RobinsConstants.h"
#import "PlayingCardDeck.h"
//#class PlayingCardDeck;
#interface PlayingCard : NSObject
+ (NSArray*) suitStrings;
+ (NSArray*) rankStrings;
+ (NSUInteger) maxRank;
- (id)initCardWithRank: (NSUInteger) r andSuit: (NSString*) s;
- (NSString*) description;
- (NSUInteger) pokerEvalRankWithDeck: (PlayingCardDeck *) deck;
- (NSAttributedString *) attributedContents;
- (BOOL) isEqual:(PlayingCard*)object;
#property (strong, nonatomic) NSString *contents;
#property (nonatomic, getter = isUsed) BOOL used;
#property (nonatomic, readonly) NSInteger rank;
#property (nonatomic, readonly, strong) NSString * suit;
#end
// PlayingCard.m
#import "PlayingCard.h"
#interface PlayingCard()
That looks like a typical "import cycle":
// In PlayingCardDeck.h:
#import "PlayingCard.h"
// In PlayingCard.h:
#import "PlayingCardDeck.h"
Replacing one of the #import statements by #class should solve the problem, e.g.
// In PlayingCardDeck.h:
#class PlayingCard; // instead of #import "PlayingCard.h"
And in the implementation file you have to import the full interface:
// In PlayingCardDeck.m:
#import "PlayingCardDeck.h"
#import "PlayingCard.h" // <-- add this one
There is something wrong in PlayingCard.h. This error causes the compiler to not know what a "PlayingCard *" is.
Can you show the code from PlayingCard.h?
Make sure the PlayingCard.m is added to your applications target! I would think it isn't (click the .m file and check your apps target in the inspector window on the right side pane)

Error: Expected specifier-qualifier-list before XXX

it did it so many times and i didn't had any problems with it, but this time i still getting the error above, my relevant code is this:
#import "PiecesChoisies.h"
#interface SelectionMobilier : UIViewController {
IBOutlet PiecesChoisies *piecesChoisies;//Error: Expected specifier-qualifier-list before PiecesChoisies
}
#end
Thanx in advance for any suggestions :)
EDIT :
I try this :
#import "PiecesChoisies.h"
#interface SelectionMobilier : UIViewController {
IBOutlet NSString *piecesChoisies;//Error: Expected specifier-qualifier-list before PiecesChoisies
}
#end
Now i got this stack:
PiecesChoisies is not recognized as a type. This may happen because it has cyclical dependencies.
The following code example illustrates the problem. Classes A and B create a circular dependency trying to import each other.
#import "B.h" // <-- A imports B
#interface A : NSObject
#end
#import "A.h"
#implementation A
#end
#import "A.h" // <-- and B imports A
#interface B : NSObject
#end
#import "B.h"
#implementation B
#end
Because the classes are never created, the compiler treats them as unknown tokens, so the error shows as Expected specifier-qualifier-list before XXX. In other words "I expected something meaningful before XXX".
To remove the circular dependency:
And add a forward class declaration (#class) on the interface file.
Move the #import from the interface to the implementation file.
The class declaration tells the compiler "don't worry, I'll define this later", so the header becomes safe to import because the conflicting definition is now out of sight on the implementation file.
Here is the result for the previous example:
#class B; // <---- #import "B.h" replaced with #class B
#interface A : NSObject
#end
#import "A.h"
#import "B.h" // <---- #import "B.h" added
#implementation A
#end
And do the same with class B:
#class A; // <---- #import "A.h" replaced with #class A
#interface B : NSObject
#end
#import "B.h"
#import "A.h" // <---- #import "A.h" added
#implementation B
#end
The problem will be located in PiecesChoisies.h. Change:
IBOutlet PiecesChoisies *piecesChoisies;
to
IBOutlet NSString *piecesChoisies;
that will confirm that the problem is located in the .h file.
If this is in a header file, use
#class PiecesChoisies;
Instead of the import statement. Import the .h file in your .m file.

Resources