似乎几乎是this question的副本,但那里的答案尚未解决问题。

第一

extern PlanningDocumentService *folderService;

第一
#import first.h

- (void)serviceDefinition
 {
    PlanningDocumentService *folderService = [_myDocumentViews objectAtIndex:[_gridView indexOfSelectedItem]];
    detail.service = folderService;
 }


#import first.h


#import second.h

+(NSArray*)getDocumentData
{
     NSString *passedCaption =  folderService.caption;
}

给出错误:
Undefined symbols for architecture i386:
  "_folderService", referenced from:
      +[GenericService getDocumentData] in GenericService.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

除了上面的文件外,我没有声明或定义folderService
任何想法都欢迎。

最佳答案

您需要定义folderService以具有全局范围:

first.m:

#import "first.h"

PlanningDocumentService *folderService = nil;

- (void)serviceDefinition
{
    folderService = [_myDocumentViews objectAtIndex:[_gridView indexOfSelectedItem]];
    detail.service = folderService;
}

10-07 23:31