我在网络上使用了同样的例子
OrderModel.h
@protocol ProductModel
@end
@interface ProductModel : JSONModel
@property (assign, nonatomic) int id;
@property (strong, nonatomic) NSString* name;
@property (assign, nonatomic) float price;
@end
@implementation ProductModel
@end
@interface OrderModel : JSONModel
@property (assign, nonatomic) int order_id;
@property (assign, nonatomic) float total_price;
@property (strong, nonatomic) NSArray<ProductModel>* products;
@end
@implementation OrderModel
@end但是当我构建这个项目时,我遇到了一个问题“重复符号”。
duplicate symbol _OBJC_CLASS_$_OrderModel
ld: 576 duplicate symbols for architecture arm64
clang: error: linker command failed with exit code 1发布于 2016-07-27 18:56:56
@实现应该出现在.m文件中,@接口应该出现在.h文件中。
您应该只导入.h文件。否则,同一个类将有多个实现。
ProductModel.h:
@interface ProductModel : JSONModel
@property (assign, nonatomic) int id;
@property (strong, nonatomic) NSString* name;
@property (assign, nonatomic) float price;
@endProductModel.m:
#import "ProductModel.h"
@implementation ProductModel
@endOrderModel.h:
@interface OrderModel : JSONModel
@property (assign, nonatomic) int order_id;
@property (assign, nonatomic) float total_price;
@property (strong, nonatomic) NSArray<ProductModel>* products;
@endOrderModel.m
#import "OrderModel.h"
@implementation OrderModel
@end例如,如果你想在视图控制器中使用ProductModel类,只需导入"ProductModel.h":
#import "ProductModel.h"https://stackoverflow.com/questions/38610602
复制相似问题