3

我知道有很多类似的问题,有点我没有找到我的案例:

我有:

#import <Foundation/Foundation.h>

@interface BSConstants : NSObject

extern NSString* const DB_COLUMN_NAME;
extern NSString* const DB_COLUMN_PRICE;
extern NSString* const DB_COLUMN_DESCRIPTION;
extern NSString* const DB_COLUMN_ICON;     
extern NSString* const DB_COLUMN_IMAGE; 

@end

#import "BSConstants.h"

@implementation BSConstants

NSString* const DB_COLUMN_NAME              = @"name";
NSString* const DB_COLUMN_PRICE             = @"price";
NSString* const DB_COLUMN_DESCRIPTION       = @"description";
NSString* const DB_COLUMN_ICON              = @"icon";
NSString* const DB_COLUMN_IMAGE             = @"image";

@end

当我尝试构建我的项目时 - 我得到:

Undefined symbols for architecture i386:
  "_CONST_SHOPPING_CART_PURCHASE_MAX_SIZE", referenced from:
      -[BSShoppingCartViewController onBuyButtonPressed:] in BSShoppingCartViewController.o
  "_NAME_CREATED_FILE", referenced from:
      -[BSImageSaver saveImageAsPng:] in BSImageSaver.o
  "_NAME_DOWNLOADS_FOLDER", referenced from:
      -[BSImageSaver saveImageAsPng:] in BSImageSaver.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

尝试访问:

#import "BSConstants.h"

 ... DB_COLUMN_NAME
4

2 回答 2

9

我发现了错误 - 我在 .h 和 .m 文件中有不同的常量名称。

于 2013-11-12T16:42:45.267 回答
1

首先尝试改变这个

extern NSString* const DB_COLUMN_NAME;extern const NSString* DB_COLUMN_NAME;

NSString* const DB_COLUMN_NAME              = @"name";

const NSString* DB_COLUMN_NAME = @"name";

另请参阅如何访问这些。

于 2012-10-09T21:52:46.053 回答