1

似乎几乎是这个问题的重复,但那里的答案并没有解决这个问题。

第一个.h

extern PlanningDocumentService *folderService;

第一个.m

#import first.h

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

第二个.h

#import first.h

秒.m

#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除了上面的文件,我没有在任何地方声明或定义。欢迎任何想法。

4

2 回答 2

4

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

第一个.m:

#import "first.h"

PlanningDocumentService *folderService = nil;

- (void)serviceDefinition
{    
    folderService = [_myDocumentViews objectAtIndex:[_gridView indexOfSelectedItem]];   
    detail.service = folderService;
}
于 2013-02-15T15:23:51.667 回答
3

PlanningDocumentService *folderServicewithin- (void)serviceDefinition使变量成为函数的局部变量,但不是全局变量。但是extern PlanningDocumentService *folderService声明了一个从未定义过的全局变量的存在。

于 2013-02-15T15:24:33.357 回答