[英]Cannot build react-native app on xcode
I'm having some issues when I build my react-native app in XCode to test on app on my iPhone. 我在XCode中构建我的react-native应用程序以在iPhone上的应用程序上进行测试时遇到一些问题。
The 4 errors are: 4个错误是:
- Expected identifier
预期标识符
- Expected identifier or '('
预期的标识符或'('
- Missing context for method declaration
方法声明缺少上下文
- '@end' must appear in an Object-C context
'@end'必须出现在Object-C上下文中
All of these errors are in my project's test .m file 3rsTests.m 所有这些错误都在我项目的测试.m文件3rsTests.m中
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>
#import <React/RCTLog.h>
#import <React/RCTRootView.h>
#define TIMEOUT_SECONDS 600
#define TEXT_TO_LOOK_FOR @"Welcome to React Native!"
@interface threeRsTests : XCTestCase
@end
@implementation 3RsTests //Error: Expected Identifier
- (BOOL)findSubviewInView:(UIView *)view matching:(BOOL(^)(UIView *view))test
{
if (test(view)) {
return YES;
}
for (UIView *subview in [view subviews]) {
if ([self findSubviewInView:subview matching:test]) {
return YES;
}
}
return NO;
}
- (void)testRendersWelcomeScreen //Error: missing context for method declaration
{
UIViewController *vc = [[[RCTSharedApplication() delegate] window] rootViewController];
NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS];
BOOL foundElement = NO;
__block NSString *redboxError = nil;
RCTSetLogFunction(^(RCTLogLevel level, RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) {
if (level >= RCTLogLevelError) {
redboxError = message;
}
});
while ([date timeIntervalSinceNow] > 0 && !foundElement && !redboxError) {
[[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
[[NSRunLoop mainRunLoop] runMode:NSRunLoopCommonModes beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
foundElement = [self findSubviewInView:vc.view matching:^BOOL(UIView *view) {
if ([view.accessibilityLabel isEqualToString:TEXT_TO_LOOK_FOR]) {
return YES;
}
return NO;
}];
}
RCTSetLogFunction(RCTDefaultLogFunction);
XCTAssertNil(redboxError, @"RedBox error: %@", redboxError);
XCTAssertTrue(foundElement, @"Couldn't find element with text '%@' in %d seconds", TEXT_TO_LOOK_FOR, TIMEOUT_SECONDS);
}
@end //Error: '@end' must appear in an Objective-C context
I'm not a Swift or Object-C programmer so these errors are quite cryptic to me. 我不是Swift或Object-C程序员,所以这些错误对我来说是很隐秘的。 I'd appreciate if anyone can give me a hand on how to get my code to compile.
如果有人可以帮助我编译代码,我将不胜感激。
This was a test file of sort and does not affect the way the name appears to the user. 这是一个测试文件,并不影响名称显示给用户的方式。 I followed @David Liaw's advice and renamed the identifier at line 17 and the app completed its built 100%
我遵循@David Liaw的建议,并在第17行将标识符重命名,应用完成了其内置的100%
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.