0
我剛開始iOS編程,正在嘗試編譯一個簡單的代碼,但無法這樣做。我收到錯誤消息,蘋果Mach-O鏈接器錯誤,架構x86_64的未定義符號
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_Player", referenced from:
objc-class-ref in AppDelegate.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
現在,我發現因爲我對代碼和我太正面臨同樣的問題,即使用同樣的環境下2個類似的問題(here和here)。我已經嘗試過他們的解決方案,但沒有成功。
正如我剛開始iOS時,我使用這tutorial作爲指導,並試圖運行他們的代碼。錯誤發生在我爲玩家變量賦予一些值的部分。代碼如下。
#import "AppDelegate.h"
#import "Player.h"
#import "PlayersViewController.h"
@interface AppDelegate()
@end
@implementation AppDelegate{
NSMutableArray *_players;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
_players = [NSMutableArray arrayWithCapacity:20];
Player *player = [[Player alloc] init];
player.name = @"Bill Evans"; //error will occur here
return YES;
}
我的架構設置如下,
的Player.h和PlayersViewController.h的代碼是完全與那些從本教程一樣。
更新
Player.h
@interface Player : NSObject
@property (nonatomic, copy) NSString *name;
@property (nonatomic, copy) NSString *game;
@property (nonatomic, assign) int rating;
@end
PlayersViewController.h
#import <UIKit/UIKit.h>
@interface PlayersViewController : UITableViewController
@property (nonatomic, strong) NSMutableArray *players;
@end
我的構建結果
聽起來像你沒有將包含'Player'類的源文件添加到Xcode目標。檢查構建日誌,看看它是否正在編譯。 – trojanfoe 2014-11-03 09:53:59
這是否意味着還需要包含播放器的.m文件?我按照教程,他們提到的所有.h文件。我將用.h文件的內容更新我的問題。 – winhung 2014-11-04 00:54:44
因此,儘管看起來很尷尬,但確實看起來我需要包含一個.m文件,併爲使用'@property'語法聲明的變量指定'@sntnthesize'語法。 – winhung 2014-11-04 01:56:37