我想初始化全局變量,但是我不知道我在做什麼錯誤,因爲我得到一個錯誤。在Obj中初始化全局變量C
現在,我有一個Globals.h文件,我導入到我的AppDelegate中。在這裏,我聲明:
#ifndef Globals_h
#define Globals_h
#endif /* Globals_h */
extern NSArray *CompetencyOne;
extern NSArray *CompetencyTwo;
extern NSArray *CompetencyThree;
extern NSArray *CompetencyFour;
extern NSArray *CompetencyFive;
extern NSArray *CompetencySix;
extern NSArray *CompetencySeven;
extern NSArray *CompetencyEight;
extern NSArray *CompetencyNine;
extern NSArray *CompetencyTen;
extern NSArray *CompetencyEleven;
extern NSArray *CompetencyTwelve;
extern NSArray *Competencies;
然後,我不知道在哪裏定義這些數組。我試着在AppDelegate.m在didFinishWithLaunchingOptions方法和視圖控制器的viewDidLoad方法,我創建了一個單獨的方法,
-(void) initializeCompetencies{ <arrays with values>}
在視圖控制器
,但我不斷收到同樣的錯誤:
Undefined symbols for architecture x86_64:
"_Competencies", referenced from:
-[QuestionViewController viewDidLoad] in QuestionViewController.o
-[QuestionViewController changed:] in QuestionViewController.o
-[QuestionViewController nextMilestone:] in QuestionViewController.o
-[QuestionViewController pressBack:] in QuestionViewController.o
-[QuestionViewController initializeCompetencies] in QuestionViewController.o
"_CompetencyEight", referenced from:
-[QuestionViewController initializeCompetencies] in QuestionViewController.o
"_CompetencyEleven", referenced from:
-[QuestionViewController initializeCompetencies] in QuestionViewController.o
"_CompetencyFive", referenced from:
-[QuestionViewController initializeCompetencies] in QuestionViewController.o
"_CompetencyFour", referenced from:
-[QuestionViewController initializeCompetencies] in QuestionViewController.o
"_CompetencyNine", referenced from:
-[QuestionViewController initializeCompetencies] in QuestionViewController.o
"_CompetencyOne", referenced from:
-[QuestionViewController initializeCompetencies] in QuestionViewController.o
"_CompetencySeven", referenced from:
-[QuestionViewController initializeCompetencies] in QuestionViewController.o
"_CompetencySix", referenced from:
-[QuestionViewController initializeCompetencies] in QuestionViewController.o
"_CompetencyTen", referenced from:
-[QuestionViewController initializeCompetencies] in QuestionViewController.o
"_CompetencyThree", referenced from:
-[QuestionViewController initializeCompetencies] in QuestionViewController.o
"_CompetencyTwelve", referenced from:
-[QuestionViewController initializeCompetencies] in QuestionViewController.o
"_CompetencyTwo", referenced from:
-[QuestionViewController initializeCompetencies] in QuestionViewController.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
任何想法如何正確地聲明和初始化全局數組?或者,如何解決這個錯誤?謝謝!
謝謝。好吧,我有一個Globals。m文件的方法 - (void)initializeCompetencies {<數組定義>}。現在,我如何將這些信息傳遞給我的viewController? –
您的Globals.m應該只是在類的頂部聲明數組,例如 NSArray * CompetencyOne = @ {....}; – davbryn