the whole game

This commit is contained in:
2026-03-02 22:04:18 +03:00
parent 816e9060b4
commit f0617a5d22
2069 changed files with 581500 additions and 0 deletions

View File

@@ -0,0 +1,146 @@
//
// IASKSettingsReader.h
// http://www.inappsettingskit.com
//
// Copyright (c) 2009:
// Luc Vandal, Edovia Inc., http://www.edovia.com
// Ortwin Gentz, FutureTap GmbH, http://www.futuretap.com
// All rights reserved.
//
// It is appreciated but not required that you give credit to Luc Vandal and Ortwin Gentz,
// as the original authors of this code. You can give credit in a blog post, a tweet or on
// a info page of your app. Also, the original authors appreciate letting them know if you use this code.
//
// This code is licensed under the BSD license that is available at: http://www.opensource.org/licenses/bsd-license.php
//
#import <Foundation/Foundation.h>
#define kIASKPreferenceSpecifiers @"PreferenceSpecifiers"
#define kIASKType @"Type"
#define kIASKTitle @"Title"
#define kIASKFooterText @"FooterText"
#define kIASKKey @"Key"
#define kIASKFile @"File"
#define kIASKDefaultValue @"DefaultValue"
#define kIASKMinimumValue @"MinimumValue"
#define kIASKMaximumValue @"MaximumValue"
#define kIASKTextOffsetPixels @"TextOffsetPixels"
#define kIASKTrueValue @"TrueValue"
#define kIASKFalseValue @"FalseValue"
#define kIASKIsSecure @"IsSecure"
#define KIASKKeyboardType @"KeyboardType"
#define kIASKAutocapitalizationType @"AutocapitalizationType"
#define kIASKAutoCorrectionType @"AutocorrectionType"
#define kIASKValues @"Values"
#define kIASKTitles @"Titles"
#define kIASKViewControllerClass @"IASKViewControllerClass"
#define kIASKViewControllerSelector @"IASKViewControllerSelector"
#define kIASKButtonClass @"IASKButtonClass"
#define kIASKButtonAction @"IASKButtonAction"
#define kIASKMailComposeToRecipents @"IASKMailComposeToRecipents"
#define kIASKMailComposeCcRecipents @"IASKMailComposeCcRecipents"
#define kIASKMailComposeBccRecipents @"IASKMailComposeBccRecipents"
#define kIASKMailComposeSubject @"IASKMailComposeSubject"
#define kIASKMailComposeBody @"IASKMailComposeBody"
#define kIASKMailComposeBodyIsHTML @"IASKMailComposeBodyIsHTML"
#define kIASKKeyboardAlphabet @"Alphabet"
#define kIASKKeyboardASCII @"Ascii"
#define kIASKKeyboardNumbersAndPunctuation @"NumbersAndPunctuation"
#define kIASKKeyboardNumberPad @"NumberPad"
#define kIASKKeyboardDecimalPad @"DecimalPad"
#define KIASKKeyboardURL @"URL"
#define kIASKKeyboardEmailAddress @"EmailAddress"
#define kIASKAutoCapNone @"None"
#define kIASKAutoCapSentences @"Sentences"
#define kIASKAutoCapWords @"Words"
#define kIASKAutoCapAllCharacters @"AllCharacters"
#define kIASKAutoCorrDefault @"Default"
#define kIASKAutoCorrNo @"No"
#define kIASKAutoCorrYes @"Yes"
#define kIASKMinimumValueImage @"MinimumValueImage"
#define kIASKMaximumValueImage @"MaximumValueImage"
#define kIASKStringIfEmpty @"StringIfEmpty"
#define kIASKPSGroupSpecifier @"PSGroupSpecifier"
#define kIASKPSToggleSwitchSpecifier @"PSToggleSwitchSpecifier"
#define kIASKPSMultiValueSpecifier @"PSMultiValueSpecifier"
#define kIASKPSSliderSpecifier @"PSSliderSpecifier"
#define kIASKPSTitleValueSpecifier @"PSTitleValueSpecifier"
#define kIASKPSTextFieldSpecifier @"PSTextFieldSpecifier"
#define kIASKPSChildPaneSpecifier @"PSChildPaneSpecifier"
#define kIASKOpenURLSpecifier @"IASKOpenURLSpecifier"
#define kIASKButtonSpecifier @"IASKButtonSpecifier"
#define kIASKMailComposeSpecifier @"IASKMailComposeSpecifier"
#define kIASKCustomViewSpecifier @"IASKCustomViewSpecifier"
#define kIASKBundleFolder @"Settings.bundle"
#define kIASKBundleFolderAlt @"InAppSettings.bundle"
#define kIASKBundleFilename @"Root.plist"
#define KIASKBundleLocaleFolderExtension @".lproj"
#define kIASKAppSettingChanged @"kAppSettingChanged"
#define kIASKSectionHeaderIndex 0
#define kIASKSliderNoImagesPadding 11
#define kIASKSliderImagesPadding 43
#define kIASKTableWidth 320
#define kIASKSpacing 5
#define kIASKMinLabelWidth 97
#define kIASKMinValueWidth 35
#define kIASKPaddingLeft 9
#define kIASKPaddingRight 10
#define kIASKHorizontalPaddingGroupTitles 19
#define kIASKVerticalPaddingGroupTitles 15
#define kIASKLabelFontSize 17
#define kIASKgrayBlueColor [UIColor colorWithRed:0.318 green:0.4 blue:0.569 alpha:1.0]
#ifndef kCFCoreFoundationVersionNumber_iPhoneOS_4_0
#define kCFCoreFoundationVersionNumber_iPhoneOS_4_0 550.32
#endif
#ifndef kCFCoreFoundationVersionNumber_iPhoneOS_4_1
#define kCFCoreFoundationVersionNumber_iPhoneOS_4_1 550.38
#endif
#define IASK_IF_IOS4_OR_GREATER(...) \
if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber_iPhoneOS_4_0) \
{ \
__VA_ARGS__ \
}
@class IASKSpecifier;
@interface IASKSettingsReader : NSObject {
NSString *_path;
NSString *_localizationTable;
NSString *_bundlePath;
NSDictionary *_settingsBundle;
NSArray *_dataSource;
NSBundle *_bundle;
}
- (id)initWithFile:(NSString*)file;
- (NSInteger)numberOfSections;
- (NSInteger)numberOfRowsForSection:(NSInteger)section;
- (IASKSpecifier*)specifierForIndexPath:(NSIndexPath*)indexPath;
- (IASKSpecifier*)specifierForKey:(NSString*)key;
- (NSString*)titleForSection:(NSInteger)section;
- (NSString*)keyForSection:(NSInteger)section;
- (NSString*)footerTextForSection:(NSInteger)section;
- (NSString*)titleForStringId:(NSString*)stringId;
- (NSString*)pathForImageNamed:(NSString*)image;
@property (nonatomic, retain) NSString *path;
@property (nonatomic, retain) NSString *localizationTable;
@property (nonatomic, retain) NSString *bundlePath;
@property (nonatomic, retain) NSDictionary *settingsBundle;
@property (nonatomic, retain) NSArray *dataSource;
@end

View File

@@ -0,0 +1,259 @@
//
// IASKSettingsReader.m
// http://www.inappsettingskit.com
//
// Copyright (c) 2009:
// Luc Vandal, Edovia Inc., http://www.edovia.com
// Ortwin Gentz, FutureTap GmbH, http://www.futuretap.com
// All rights reserved.
//
// It is appreciated but not required that you give credit to Luc Vandal and Ortwin Gentz,
// as the original authors of this code. You can give credit in a blog post, a tweet or on
// a info page of your app. Also, the original authors appreciate letting them know if you use this code.
//
// This code is licensed under the BSD license that is available at: http://www.opensource.org/licenses/bsd-license.php
//
#import "IASKSettingsReader.h"
#import "IASKSpecifier.h"
@interface IASKSettingsReader (private)
- (void)_reinterpretBundle:(NSDictionary*)settingsBundle;
- (BOOL)_sectionHasHeading:(NSInteger)section;
- (NSString *)platformSuffix;
- (NSString *)locateSettingsFile:(NSString *)file;
@end
@implementation IASKSettingsReader
@synthesize path=_path,
localizationTable=_localizationTable,
bundlePath=_bundlePath,
settingsBundle=_settingsBundle,
dataSource=_dataSource;
- (id)init {
return [self initWithFile:@"Root"];
}
- (id)initWithFile:(NSString*)file {
if ((self=[super init])) {
self.path = [self locateSettingsFile: file];
[self setSettingsBundle:[NSDictionary dictionaryWithContentsOfFile:self.path]];
self.bundlePath = [self.path stringByDeletingLastPathComponent];
_bundle = [[NSBundle bundleWithPath:[self bundlePath]] retain];
// Look for localization file
self.localizationTable = [self.settingsBundle objectForKey:@"StringsTable"];
NSLog(@"Loc table: %@. bundle: %@ (%p)\n", self.localizationTable, _bundlePath, _bundle);
if (!self.localizationTable)
{
// Look for localization file using filename
self.localizationTable = [[[[self.path stringByDeletingPathExtension] // removes '.plist'
stringByDeletingPathExtension] // removes potential '.inApp'
lastPathComponent] // strip absolute path
stringByReplacingOccurrencesOfString:[self platformSuffix] withString:@""]; // removes potential '~device' (~ipad, ~iphone)
NSLog(@"Settings string filename: %@\n", self.localizationTable);
if([_bundle pathForResource:self.localizationTable ofType:@"strings"] == nil){
// Could not find the specified localization: use default
self.localizationTable = @"Root";
NSLog(@"Couldn't find file though..\n");
}
}
if (_settingsBundle) {
[self _reinterpretBundle:_settingsBundle];
}
}
return self;
}
- (void)dealloc {
[_path release], _path = nil;
[_localizationTable release], _localizationTable = nil;
[_bundlePath release], _bundlePath = nil;
[_settingsBundle release], _settingsBundle = nil;
[_dataSource release], _dataSource = nil;
[_bundle release], _bundle = nil;
[super dealloc];
}
- (void)_reinterpretBundle:(NSDictionary*)settingsBundle {
NSArray *preferenceSpecifiers = [settingsBundle objectForKey:kIASKPreferenceSpecifiers];
NSInteger sectionCount = -1;
NSMutableArray *dataSource = [[[NSMutableArray alloc] init] autorelease];
for (NSDictionary *specifier in preferenceSpecifiers) {
if ([(NSString*)[specifier objectForKey:kIASKType] isEqualToString:kIASKPSGroupSpecifier]) {
NSMutableArray *newArray = [[NSMutableArray alloc] init];
[newArray addObject:specifier];
[dataSource addObject:newArray];
[newArray release];
sectionCount++;
}
else {
if (sectionCount == -1) {
NSMutableArray *newArray = [[NSMutableArray alloc] init];
[dataSource addObject:newArray];
[newArray release];
sectionCount++;
}
IASKSpecifier *newSpecifier = [[IASKSpecifier alloc] initWithSpecifier:specifier];
[(NSMutableArray*)[dataSource objectAtIndex:sectionCount] addObject:newSpecifier];
[newSpecifier release];
}
}
[self setDataSource:dataSource];
}
- (BOOL)_sectionHasHeading:(NSInteger)section {
return [[[[self dataSource] objectAtIndex:section] objectAtIndex:0] isKindOfClass:[NSDictionary class]];
}
- (NSInteger)numberOfSections {
return [[self dataSource] count];
}
- (NSInteger)numberOfRowsForSection:(NSInteger)section {
int headingCorrection = [self _sectionHasHeading:section] ? 1 : 0;
return [(NSArray*)[[self dataSource] objectAtIndex:section] count] - headingCorrection;
}
- (IASKSpecifier*)specifierForIndexPath:(NSIndexPath*)indexPath {
int headingCorrection = [self _sectionHasHeading:indexPath.section] ? 1 : 0;
IASKSpecifier *specifier = [[[self dataSource] objectAtIndex:indexPath.section] objectAtIndex:(indexPath.row+headingCorrection)];
specifier.settingsReader = self;
return specifier;
}
- (IASKSpecifier*)specifierForKey:(NSString*)key {
for (NSArray *specifiers in _dataSource) {
for (id sp in specifiers) {
if ([sp isKindOfClass:[IASKSpecifier class]]) {
if ([[sp key] isEqualToString:key]) {
return sp;
}
}
}
}
return nil;
}
- (NSString*)titleForSection:(NSInteger)section {
if ([self _sectionHasHeading:section]) {
NSDictionary *dict = [[[self dataSource] objectAtIndex:section] objectAtIndex:kIASKSectionHeaderIndex];
return [_bundle localizedStringForKey:[dict objectForKey:kIASKTitle] value:[dict objectForKey:kIASKTitle] table:self.localizationTable];
}
return nil;
}
- (NSString*)keyForSection:(NSInteger)section {
if ([self _sectionHasHeading:section]) {
return [[[[self dataSource] objectAtIndex:section] objectAtIndex:kIASKSectionHeaderIndex] objectForKey:kIASKKey];
}
return nil;
}
- (NSString*)footerTextForSection:(NSInteger)section {
if ([self _sectionHasHeading:section]) {
NSDictionary *dict = [[[self dataSource] objectAtIndex:section] objectAtIndex:kIASKSectionHeaderIndex];
return [_bundle localizedStringForKey:[dict objectForKey:kIASKFooterText] value:[dict objectForKey:kIASKFooterText] table:self.localizationTable];
}
return nil;
}
- (NSString*)titleForStringId:(NSString*)stringId {
return [_bundle localizedStringForKey:stringId value:stringId table:self.localizationTable];
}
- (NSString*)pathForImageNamed:(NSString*)image {
return [[self bundlePath] stringByAppendingPathComponent:image];
}
- (NSString *)platformSuffix {
BOOL isPad = NO;
#if (__IPHONE_OS_VERSION_MAX_ALLOWED >= 30200)
isPad = UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad;
#endif
return isPad ? @"~ipad" : @"~iphone";
}
- (NSString *)file:(NSString *)file
withBundle:(NSString *)bundle
suffix:(NSString *)suffix
extension:(NSString *)extension {
NSString *appBundle = [[NSBundle mainBundle] bundlePath];
bundle = [appBundle stringByAppendingPathComponent:bundle];
file = [file stringByAppendingFormat:@"%@%@", suffix, extension];
return [bundle stringByAppendingPathComponent:file];
}
- (NSString *)locateSettingsFile: (NSString *)file {
// The file is searched in the following order:
//
// InAppSettings.bundle/FILE~DEVICE.inApp.plist
// InAppSettings.bundle/FILE.inApp.plist
// InAppSettings.bundle/FILE~DEVICE.plist
// InAppSettings.bundle/FILE.plist
// Settings.bundle/FILE~DEVICE.inApp.plist
// Settings.bundle/FILE.inApp.plist
// Settings.bundle/FILE~DEVICE.plist
// Settings.bundle/FILE.plist
//
// where DEVICE is either "iphone" or "ipad" depending on the current
// interface idiom.
//
// Settings.app uses the ~DEVICE suffixes since iOS 4.0. There are some
// differences from this implementation:
// - For an iPhone-only app running on iPad, Settings.app will not use the
// ~iphone suffix. There is no point in using these suffixes outside
// of universal apps anyway.
// - This implementation uses the device suffixes on iOS 3.x as well.
// - also check current locale (short only)
NSArray *bundles =
[NSArray arrayWithObjects:kIASKBundleFolderAlt, kIASKBundleFolder, nil];
NSArray *extensions =
[NSArray arrayWithObjects:@".inApp.plist", @".plist", nil];
NSArray *suffixes =
[NSArray arrayWithObjects:[self platformSuffix], @"", nil];
NSArray *languages =
[NSArray arrayWithObjects:[[[NSLocale preferredLanguages] objectAtIndex:0] stringByAppendingString:KIASKBundleLocaleFolderExtension], @"", nil];
NSString *path = nil;
NSFileManager *fileManager = [NSFileManager defaultManager];
for (NSString *bundle in bundles) {
for (NSString *extension in extensions) {
for (NSString *suffix in suffixes) {
for (NSString *language in languages) {
path = [self file:file
withBundle:[bundle stringByAppendingPathComponent:language]
suffix:suffix
extension:extension];
if ([fileManager fileExistsAtPath:path]) {
goto exitFromNestedLoop;
}
}
}
}
}
exitFromNestedLoop:
return path;
}
@end

View File

@@ -0,0 +1,39 @@
//
// IASKSettingsStore.h
// http://www.inappsettingskit.com
//
// Copyright (c) 2010:
// Luc Vandal, Edovia Inc., http://www.edovia.com
// Ortwin Gentz, FutureTap GmbH, http://www.futuretap.com
// Marc-Etienne M.Léveillé, Edovia Inc., http://www.edovia.com
// All rights reserved.
//
// It is appreciated but not required that you give credit to Luc Vandal and Ortwin Gentz,
// as the original authors of this code. You can give credit in a blog post, a tweet or on
// a info page of your app. Also, the original authors appreciate letting them know if you use this code.
//
// This code is licensed under the BSD license that is available at: http://www.opensource.org/licenses/bsd-license.php
//
#import <Foundation/Foundation.h>
@protocol IASKSettingsStore <NSObject>
@required
- (void)setBool:(BOOL)value forKey:(NSString*)key;
- (void)setFloat:(float)value forKey:(NSString*)key;
- (void)setDouble:(double)value forKey:(NSString*)key;
- (void)setInteger:(int)value forKey:(NSString*)key;
- (void)setObject:(id)value forKey:(NSString*)key;
- (BOOL)boolForKey:(NSString*)key;
- (float)floatForKey:(NSString*)key;
- (double)doubleForKey:(NSString*)key;
- (int)integerForKey:(NSString*)key;
- (id)objectForKey:(NSString*)key;
- (BOOL)synchronize; // Write settings to a permanant storage. Returns YES on success, NO otherwise
@end
@interface IASKAbstractSettingsStore : NSObject <IASKSettingsStore> {
}
@end

View File

@@ -0,0 +1,68 @@
//
// IASKSettingsStore.m
// http://www.inappsettingskit.com
//
// Copyright (c) 2010:
// Luc Vandal, Edovia Inc., http://www.edovia.com
// Ortwin Gentz, FutureTap GmbH, http://www.futuretap.com
// Marc-Etienne M.Léveillé, Edovia Inc., http://www.edovia.com
// All rights reserved.
//
// It is appreciated but not required that you give credit to Luc Vandal and Ortwin Gentz,
// as the original authors of this code. You can give credit in a blog post, a tweet or on
// a info page of your app. Also, the original authors appreciate letting them know if you use this code.
//
// This code is licensed under the BSD license that is available at: http://www.opensource.org/licenses/bsd-license.php
//
#import "IASKSettingsStore.h"
@implementation IASKAbstractSettingsStore
- (void)setObject:(id)value forKey:(NSString*)key {
[NSException raise:@"Unimplemented"
format:@"setObject:forKey: must be implemented in subclasses of IASKAbstractSettingsStore"];
}
- (id)objectForKey:(NSString*)key {
[NSException raise:@"Unimplemented"
format:@"objectForKey: must be implemented in subclasses of IASKAbstractSettingsStore"];
return nil;
}
- (void)setBool:(BOOL)value forKey:(NSString*)key {
[self setObject:[NSNumber numberWithBool:value] forKey:key];
}
- (void)setFloat:(float)value forKey:(NSString*)key {
[self setObject:[NSNumber numberWithFloat:value] forKey:key];
}
- (void)setInteger:(int)value forKey:(NSString*)key {
[self setObject:[NSNumber numberWithInt:value] forKey:key];
}
- (void)setDouble:(double)value forKey:(NSString*)key {
[self setObject:[NSNumber numberWithDouble:value] forKey:key];
}
- (BOOL)boolForKey:(NSString*)key {
return [[self objectForKey:key] boolValue];
}
- (float)floatForKey:(NSString*)key {
return [[self objectForKey:key] floatValue];
}
- (int)integerForKey:(NSString*)key {
return [[self objectForKey:key] intValue];
}
- (double)doubleForKey:(NSString*)key {
return [[self objectForKey:key] doubleValue];
}
- (BOOL)synchronize {
return NO;
}
@end

View File

@@ -0,0 +1,28 @@
//
// IASKSettingsStoreFile.h
// http://www.inappsettingskit.com
//
// Copyright (c) 2010:
// Luc Vandal, Edovia Inc., http://www.edovia.com
// Ortwin Gentz, FutureTap GmbH, http://www.futuretap.com
// Marc-Etienne M.Léveillé, Edovia Inc., http://www.edovia.com
// All rights reserved.
//
// It is appreciated but not required that you give credit to Luc Vandal and Ortwin Gentz,
// as the original authors of this code. You can give credit in a blog post, a tweet or on
// a info page of your app. Also, the original authors appreciate letting them know if you use this code.
//
// This code is licensed under the BSD license that is available at: http://www.opensource.org/licenses/bsd-license.php
//
#import <Foundation/Foundation.h>
#import "IASKSettingsStore.h"
@interface IASKSettingsStoreFile : IASKAbstractSettingsStore {
NSString * _filePath;
NSMutableDictionary * _dict;
}
- (id)initWithPath:(NSString*)path;
@end

View File

@@ -0,0 +1,54 @@
//
// IASKSettingsStoreFile.m
// http://www.inappsettingskit.com
//
// Copyright (c) 2010:
// Luc Vandal, Edovia Inc., http://www.edovia.com
// Ortwin Gentz, FutureTap GmbH, http://www.futuretap.com
// Marc-Etienne M.Léveillé, Edovia Inc., http://www.edovia.com
// All rights reserved.
//
// It is appreciated but not required that you give credit to Luc Vandal and Ortwin Gentz,
// as the original authors of this code. You can give credit in a blog post, a tweet or on
// a info page of your app. Also, the original authors appreciate letting them know if you use this code.
//
// This code is licensed under the BSD license that is available at: http://www.opensource.org/licenses/bsd-license.php
//
#import "IASKSettingsStoreFile.h"
@implementation IASKSettingsStoreFile
- (id)initWithPath:(NSString*)path {
if((self = [super init])) {
_filePath = [path retain];
_dict = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
if(_dict == nil) {
_dict = [[NSMutableDictionary alloc] init];
}
}
return self;
}
- (void)dealloc {
[_dict release], _dict = nil;
[_filePath release], _filePath = nil;
[super dealloc];
}
- (void)setObject:(id)value forKey:(NSString *)key {
[_dict setObject:value forKey:key];
}
- (id)objectForKey:(NSString *)key {
return [_dict objectForKey:key];
}
- (BOOL)synchronize {
return [_dict writeToFile:_filePath atomically:YES];
}
@end

View File

@@ -0,0 +1,25 @@
//
// IASKSettingsStoreUserDefaults.h
// http://www.inappsettingskit.com
//
// Copyright (c) 2010:
// Luc Vandal, Edovia Inc., http://www.edovia.com
// Ortwin Gentz, FutureTap GmbH, http://www.futuretap.com
// Marc-Etienne M.Léveillé, Edovia Inc., http://www.edovia.com
// All rights reserved.
//
// It is appreciated but not required that you give credit to Luc Vandal and Ortwin Gentz,
// as the original authors of this code. You can give credit in a blog post, a tweet or on
// a info page of your app. Also, the original authors appreciate letting them know if you use this code.
//
// This code is licensed under the BSD license that is available at: http://www.opensource.org/licenses/bsd-license.php
//
#import <Foundation/Foundation.h>
#import "IASKSettingsStore.h"
@interface IASKSettingsStoreUserDefaults : IASKAbstractSettingsStore {
}
@end

View File

@@ -0,0 +1,67 @@
//
// IASKSettingsStoreUserDefaults.m
// http://www.inappsettingskit.com
//
// Copyright (c) 2010:
// Luc Vandal, Edovia Inc., http://www.edovia.com
// Ortwin Gentz, FutureTap GmbH, http://www.futuretap.com
// Marc-Etienne M.Léveillé, Edovia Inc., http://www.edovia.com
// All rights reserved.
//
// It is appreciated but not required that you give credit to Luc Vandal and Ortwin Gentz,
// as the original authors of this code. You can give credit in a blog post, a tweet or on
// a info page of your app. Also, the original authors appreciate letting them know if you use this code.
//
// This code is licensed under the BSD license that is available at: http://www.opensource.org/licenses/bsd-license.php
//
#import "IASKSettingsStoreUserDefaults.h"
@implementation IASKSettingsStoreUserDefaults
- (void)setBool:(BOOL)value forKey:(NSString*)key {
[[NSUserDefaults standardUserDefaults] setBool:value forKey:key];
}
- (void)setFloat:(float)value forKey:(NSString*)key {
[[NSUserDefaults standardUserDefaults] setFloat:value forKey:key];
}
- (void)setDouble:(double)value forKey:(NSString*)key {
[[NSUserDefaults standardUserDefaults] setDouble:value forKey:key];
}
- (void)setInteger:(int)value forKey:(NSString*)key {
[[NSUserDefaults standardUserDefaults] setInteger:value forKey:key];
}
- (void)setObject:(id)value forKey:(NSString*)key {
[[NSUserDefaults standardUserDefaults] setObject:value forKey:key];
}
- (BOOL)boolForKey:(NSString*)key {
return [[NSUserDefaults standardUserDefaults] boolForKey:key];
}
- (float)floatForKey:(NSString*)key {
return [[NSUserDefaults standardUserDefaults] floatForKey:key];
}
- (double)doubleForKey:(NSString*)key {
return [[NSUserDefaults standardUserDefaults] doubleForKey:key];
}
- (int)integerForKey:(NSString*)key {
return [[NSUserDefaults standardUserDefaults] integerForKey:key];
}
- (id)objectForKey:(NSString*)key {
return [[NSUserDefaults standardUserDefaults] objectForKey:key];
}
- (BOOL)synchronize {
return [[NSUserDefaults standardUserDefaults] synchronize];
}
@end

View File

@@ -0,0 +1,63 @@
//
// IASKSpecifier.h
// http://www.inappsettingskit.com
//
// Copyright (c) 2009:
// Luc Vandal, Edovia Inc., http://www.edovia.com
// Ortwin Gentz, FutureTap GmbH, http://www.futuretap.com
// All rights reserved.
//
// It is appreciated but not required that you give credit to Luc Vandal and Ortwin Gentz,
// as the original authors of this code. You can give credit in a blog post, a tweet or on
// a info page of your app. Also, the original authors appreciate letting them know if you use this code.
//
// This code is licensed under the BSD license that is available at: http://www.opensource.org/licenses/bsd-license.php
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@class IASKSettingsReader;
@interface IASKSpecifier : NSObject {
NSDictionary *_specifierDict;
NSDictionary *_multipleValuesDict;
IASKSettingsReader *_settingsReader;
}
@property (nonatomic, retain) NSDictionary *specifierDict;
@property (nonatomic, assign) IASKSettingsReader *settingsReader;
- (id)initWithSpecifier:(NSDictionary*)specifier;
- (NSString*)localizedObjectForKey:(NSString*)key;
- (NSString*)title;
- (NSString*)key;
- (NSString*)type;
- (NSString*)titleForCurrentValue:(id)currentValue;
- (NSInteger)multipleValuesCount;
- (NSArray*)multipleValues;
- (NSArray*)multipleTitles;
- (NSString*)file;
- (id)defaultValue;
- (id)defaultStringValue;
- (BOOL)defaultBoolValue;
- (id)trueValue;
- (id)falseValue;
- (float)minimumValue;
- (float)maximumValue;
- (int)textOffsetPixels;
- (NSString*)minimumValueImage;
- (NSString*)maximumValueImage;
- (BOOL)isSecure;
- (UIKeyboardType)keyboardType;
- (UITextAutocapitalizationType)autocapitalizationType;
- (UITextAutocorrectionType)autoCorrectionType;
- (NSString*)footerText;
- (NSString*)stringIfEmpty;
- (Class)viewControllerClass;
- (SEL)viewControllerSelector;
-(Class)buttonClass;
-(SEL)buttonAction;
-(BOOL)hasSpecified:(NSString*)key;
@end

View File

@@ -0,0 +1,256 @@
//
// IASKSpecifier.m
// http://www.inappsettingskit.com
//
// Copyright (c) 2009:
// Luc Vandal, Edovia Inc., http://www.edovia.com
// Ortwin Gentz, FutureTap GmbH, http://www.futuretap.com
// All rights reserved.
//
// It is appreciated but not required that you give credit to Luc Vandal and Ortwin Gentz,
// as the original authors of this code. You can give credit in a blog post, a tweet or on
// a info page of your app. Also, the original authors appreciate letting them know if you use this code.
//
// This code is licensed under the BSD license that is available at: http://www.opensource.org/licenses/bsd-license.php
//
#import "IASKSpecifier.h"
#import "IASKSettingsReader.h"
@interface IASKSpecifier ()
@property (nonatomic, retain) NSDictionary *multipleValuesDict;
- (void)_reinterpretValues:(NSDictionary*)specifierDict;
@end
@implementation IASKSpecifier
@synthesize specifierDict=_specifierDict;
@synthesize multipleValuesDict=_multipleValuesDict;
@synthesize settingsReader = _settingsReader;
- (id)initWithSpecifier:(NSDictionary*)specifier {
if ((self = [super init])) {
[self setSpecifierDict:specifier];
if ([[self type] isEqualToString:kIASKPSMultiValueSpecifier] ||
[[self type] isEqualToString:kIASKPSTitleValueSpecifier]) {
[self _reinterpretValues:[self specifierDict]];
}
}
return self;
}
- (void)dealloc {
[_specifierDict release], _specifierDict = nil;
[_multipleValuesDict release], _multipleValuesDict = nil;
_settingsReader = nil;
[super dealloc];
}
-(BOOL)hasSpecified:(NSString*)key {
return [_specifierDict objectForKey:key] != nil;
}
- (void)_reinterpretValues:(NSDictionary*)specifierDict {
NSArray *values = [_specifierDict objectForKey:kIASKValues];
NSArray *titles = [_specifierDict objectForKey:kIASKTitles];
NSMutableDictionary *multipleValuesDict = [[[NSMutableDictionary alloc] init] autorelease];
if (values) {
[multipleValuesDict setObject:values forKey:kIASKValues];
}
if (titles) {
[multipleValuesDict setObject:titles forKey:kIASKTitles];
}
[self setMultipleValuesDict:multipleValuesDict];
}
- (NSString*)localizedObjectForKey:(NSString*)key {
return [self.settingsReader titleForStringId:[_specifierDict objectForKey:key]];
}
- (NSString*)title {
return [self localizedObjectForKey:kIASKTitle];
}
- (NSString*)footerText {
return [self localizedObjectForKey:kIASKFooterText];
}
- (NSString*)stringIfEmpty {
return [_specifierDict objectForKey:kIASKStringIfEmpty];
}
-(Class) viewControllerClass {
return NSClassFromString([_specifierDict objectForKey:kIASKViewControllerClass]);
}
-(SEL) viewControllerSelector {
return NSSelectorFromString([_specifierDict objectForKey:kIASKViewControllerSelector]);
}
-(Class)buttonClass {
return NSClassFromString([_specifierDict objectForKey:kIASKButtonClass]);
}
-(SEL)buttonAction {
return NSSelectorFromString([_specifierDict objectForKey:kIASKButtonAction]);
}
- (NSString*)key {
return [_specifierDict objectForKey:kIASKKey];
}
- (NSString*)type {
return [_specifierDict objectForKey:kIASKType];
}
- (NSString*)titleForCurrentValue:(id)currentValue {
NSArray *values = [self multipleValues];
NSArray *titles = [self multipleTitles];
if (values.count != titles.count) {
return nil;
}
NSInteger keyIndex = [values indexOfObject:currentValue];
if (keyIndex == NSNotFound) {
return nil;
}
@try {
return [self.settingsReader titleForStringId:[titles objectAtIndex:keyIndex]];
}
@catch (NSException * e) {}
return nil;
}
- (NSInteger)multipleValuesCount {
return [[_multipleValuesDict objectForKey:kIASKValues] count];
}
- (NSArray*)multipleValues {
return [_multipleValuesDict objectForKey:kIASKValues];
}
- (NSArray*)multipleTitles {
return [_multipleValuesDict objectForKey:kIASKTitles];
}
- (NSString*)file {
return [_specifierDict objectForKey:kIASKFile];
}
- (id)defaultValue {
return [_specifierDict objectForKey:kIASKDefaultValue];
}
- (id)defaultStringValue {
return [[_specifierDict objectForKey:kIASKDefaultValue] description];
}
- (BOOL)defaultBoolValue {
id defaultValue = [self defaultValue];
if ([defaultValue isEqual:[self trueValue]]) {
return YES;
}
if ([defaultValue isEqual:[self falseValue]]) {
return NO;
}
return [defaultValue boolValue];
}
- (id)trueValue {
return [_specifierDict objectForKey:kIASKTrueValue];
}
- (id)falseValue {
return [_specifierDict objectForKey:kIASKFalseValue];
}
- (float)minimumValue {
return [[_specifierDict objectForKey:kIASKMinimumValue] floatValue];
}
- (float)maximumValue {
return [[_specifierDict objectForKey:kIASKMaximumValue] floatValue];
}
- (int)textOffsetPixels {
return [[_specifierDict objectForKey:kIASKTextOffsetPixels] intValue];
}
- (NSString*)minimumValueImage {
return [_specifierDict objectForKey:kIASKMinimumValueImage];
}
- (NSString*)maximumValueImage {
return [_specifierDict objectForKey:kIASKMaximumValueImage];
}
- (BOOL)isSecure {
return [[_specifierDict objectForKey:kIASKIsSecure] boolValue];
}
- (UIKeyboardType)keyboardType {
if ([[_specifierDict objectForKey:KIASKKeyboardType] isEqualToString:kIASKKeyboardAlphabet]) {
return UIKeyboardTypeDefault;
}
else if ([[_specifierDict objectForKey:KIASKKeyboardType] isEqualToString:kIASKKeyboardASCII]) {
return UIKeyboardTypeASCIICapable;
}
else if ([[_specifierDict objectForKey:KIASKKeyboardType] isEqualToString:kIASKKeyboardNumbersAndPunctuation]) {
return UIKeyboardTypeNumbersAndPunctuation;
}
else if ([[_specifierDict objectForKey:KIASKKeyboardType] isEqualToString:kIASKKeyboardNumberPad]) {
return UIKeyboardTypeNumberPad;
}
else if ([[_specifierDict objectForKey:KIASKKeyboardType] isEqualToString:kIASKKeyboardDecimalPad]) {
if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber_iPhoneOS_4_1) {
return UIKeyboardTypeDecimalPad;
}
else {
return UIKeyboardTypeNumbersAndPunctuation;
}
}
else if ([[_specifierDict objectForKey:KIASKKeyboardType] isEqualToString:KIASKKeyboardURL]) {
return UIKeyboardTypeURL;
}
else if ([[_specifierDict objectForKey:KIASKKeyboardType] isEqualToString:kIASKKeyboardEmailAddress]) {
return UIKeyboardTypeEmailAddress;
}
return UIKeyboardTypeDefault;
}
- (UITextAutocapitalizationType)autocapitalizationType {
if ([[_specifierDict objectForKey:kIASKAutocapitalizationType] isEqualToString:kIASKAutoCapNone]) {
return UITextAutocapitalizationTypeNone;
}
else if ([[_specifierDict objectForKey:kIASKAutocapitalizationType] isEqualToString:kIASKAutoCapSentences]) {
return UITextAutocapitalizationTypeSentences;
}
else if ([[_specifierDict objectForKey:kIASKAutocapitalizationType] isEqualToString:kIASKAutoCapWords]) {
return UITextAutocapitalizationTypeWords;
}
else if ([[_specifierDict objectForKey:kIASKAutocapitalizationType] isEqualToString:kIASKAutoCapAllCharacters]) {
return UITextAutocapitalizationTypeAllCharacters;
}
return UITextAutocapitalizationTypeNone;
}
- (UITextAutocorrectionType)autoCorrectionType {
if ([[_specifierDict objectForKey:kIASKAutoCorrectionType] isEqualToString:kIASKAutoCorrDefault]) {
return UITextAutocorrectionTypeDefault;
}
else if ([[_specifierDict objectForKey:kIASKAutoCorrectionType] isEqualToString:kIASKAutoCorrNo]) {
return UITextAutocorrectionTypeNo;
}
else if ([[_specifierDict objectForKey:kIASKAutoCorrectionType] isEqualToString:kIASKAutoCorrYes]) {
return UITextAutocorrectionTypeYes;
}
return UITextAutocorrectionTypeDefault;
}
@end