Slinky
Slinky

Reputation: 5832

Storing an iOS Application Constant in Objective-C

I have a few unicode characters (musical flat and sharp symbols) that I currently have defined in a class:

#import <Foundation/Foundation.h>

#define kSongsSharpSymbol [NSString stringWithFormat:@"\U0000266F"]
#define kSongsFlatSymbol [NSString stringWithFormat:@"\U0000266D"]

@interface Song : NSObject {

 //...

}

As the application grows I think these types of constants would be better off placed someplace that is available to the application files without having to include the class.

Questions

  1. Am I defining the unicode characters correctly? It works but that doesn't mean it's right
  2. Where, ideally, should I be placing these types of constants?

Cheers and Thanks!

Upvotes: 3

Views: 1298

Answers (1)

Slinky
Slinky

Reputation: 5832

I solved this by creating a custom class like so, and then adding it to my precompiled header file:

//Constants.h
#import <Foundation/Foundation.h>

FOUNDATION_EXPORT NSString *const kSongsSharpSymbol;
FOUNDATION_EXPORT NSString *const kSongsFlatSymbol;


//Constants.m
#import "Constants.h"

NSString *const kSongsSharpSymbol = @"\U0000266F";
NSString *const kSongsFlatSymbol = @"\U0000266D";

 //.pch file
#import <Availability.h>

#ifndef __IPHONE_4_0
#warning "This project uses features only available in iOS SDK 4.0 and later."
#endif

 #ifdef __OBJC__
  #import <UIKit/UIKit.h>
  #import <Foundation/Foundation.h>
  #import "Constants.h"

#endif

Upvotes: 3

Related Questions