Linking External Constants -- Objective C
In an e开发者_JS百科arlier answer about external constants, the preferred answer says
"Constants.m should be added to your application/framework's target so that it is linked in to the final product."
I am using Xcode 4 and can't see how this is done. Can someone help me with this?
I'm trying to move my user interface constants to a single file so I can manage them from one place. (I'm not interested in using a singleton for this case.)
Based on the answer provided below, I was able to make this work. The .h and .m files are very simple:
Constants.h
#pragma mark - Calendar Settings
extern const CGSize _kTileSize;
Constants.m
#import "Constants.h"
#pragma mark - Calendar Settings
const CGSize _kTileSize = { 46.f, 44.f };
Note that there is no interface and no implementation, Since it is not a class. I did add the files as instructed in the answer, except I selected new file... objective c class. Then I deleted the interface and implementation sections.
Now that I have it working I will add more constants to the file.
Go as follow:
1.File
2.New
3.New file
4.Objective C file
File -> New -> New file -> Objective C file.
精彩评论