Home > Software engineering >  format error when adding to AppDelegate.m
format error when adding to AppDelegate.m

Time:07-21

I am following react-native-codepush doc to add the following block to AppDelegate.m in React native 0.68.0/Xcode 13:

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
  #if DEBUG
    return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
  #else
    return [CodePush bundleURL];
  #endif
}

Here is the AppDelegate.m after change:

#import <React/RCTBridgeDelegate.h>
#import <UIKit/UIKit.h>
#import <CodePush/CodePush.h> /* for rn codepush */

@interface AppDelegate : UIResponder <UIApplicationDelegate, RCTBridgeDelegate>

@property (nonatomic, strong) UIWindow *window;

/* for rn code push */
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
  #if DEBUG
    return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
  #else
    return [CodePush bundleURL];
  #endif
}

@end

However there is error saying: Expected ';' after method prototype. I am not an expert on Xcode/IOS, what is really missing here? Many thanks.

CodePudding user response:

Definition of method should not be included in @interface ... end, Only properties and methods are declared in @interface ... end

You are trying to write the definition of method in,

@interface 
...
@end

Instead add the method in

@implementation 
...
@end

So after adding your code, it should look like below,

@implementation 

/* for rn code push */
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
  #if DEBUG
    return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
  #else
    return [CodePush bundleURL];
  #endif
}

@end
  • Related