XCTestCase超类方法对子类不可见

问题描述 投票:0回答:1

我创建了以下XCTestCase超类:

//  FileNameTest.h

#import <XCTest/XCTest.h>

NS_ASSUME_NONNULL_BEGIN

@interface FileNameTest : XCTestCase

@end

NS_ASSUME_NONNULL_END

//  FileNameTest.m

#import "FileNameTest.h"

@implementation FileNameTest
- (void)setUp {
    [super setUp];
}

- (void)tearDown {
    [super tearDown];
}

- (void)helloMessage{
  NSLog(@"Hello");
}

@end

和一个调用超类方法的子类:

//  FilenamePatternTest1.m

#import "FileNameTest.h"

@interface FilenamePatternTest1 : FileNameTest

@end

@implementation FilenamePatternTest1

- (void)testExample {
  [self helloMessage];
}

@end

但是子类不会编译。错误消息显示为:

'FilenamePatternTest1'的无可见@interface声明了选择器'helloMessage'

xcode inheritance xctest
1个回答
0
投票

Objective-C看不到.m文件中的声明。您将需要在超类的.h文件中声明要调用的方法。

© www.soinside.com 2019 - 2024. All rights reserved.