(Apple) Objective C refactoring:

All properties are marked (nonatomic)
	All table view cell reuse identifiers are now constant string objects.
	Where appropriate all calls to [RetroArch_iOS get] are replaced with self.navigationController.
	All calls to objc_setAssociatedObject use proper keys rather than string literals.
This commit is contained in:
meancoot 2013-09-24 20:03:47 -04:00
parent 8272d1cd68
commit 0ddf198875
9 changed files with 71 additions and 56 deletions

View File

@ -37,9 +37,9 @@
- (void)loadingCore:(RAModuleInfo*)core withFile:(const char*)file;
- (void)unloadingCore:(RAModuleInfo*)core;
@property (strong, nonatomic) NSString* configDirectory; // e.g. /var/mobile/Documents/.RetroArch
@property (strong, nonatomic) NSString* globalConfigFile; // e.g. /var/mobile/Documents/.RetroArch/retroarch.cfg
@property (strong, nonatomic) NSString* coreDirectory; // e.g. /Applications/RetroArch.app/modules
@property (nonatomic) NSString* configDirectory; // e.g. /var/mobile/Documents/.RetroArch
@property (nonatomic) NSString* globalConfigFile; // e.g. /var/mobile/Documents/.RetroArch/retroarch.cfg
@property (nonatomic) NSString* coreDirectory; // e.g. /Applications/RetroArch.app/modules
@end

View File

@ -25,13 +25,13 @@
extern NSArray* apple_get_modules();
@interface RAModuleInfo : NSObject
@property NSString* path; // e.g. /path/to/corename_libretro.dylib
@property NSString* baseName; // e.g. corename_libretro
@property core_info_t* info;
@property config_file_t* data;
@property NSString* description; // Friendly name from config file, else just the filename
@property NSString* customConfigFile; // Path where custom config file would reside
@property NSString* configFile; // Path to effective config file
@property (nonatomic) NSString* path; // e.g. /path/to/corename_libretro.dylib
@property (nonatomic) NSString* baseName; // e.g. corename_libretro
@property (nonatomic) core_info_t* info;
@property (nonatomic) config_file_t* data;
@property (nonatomic) NSString* description; // Friendly name from config file, else just the filename
@property (nonatomic) NSString* customConfigFile; // Path where custom config file would reside
@property (nonatomic) NSString* configFile; // Path to effective config file
- (bool)supportsFileAtPath:(NSString*)path;

View File

@ -92,11 +92,13 @@ NSArray* apple_get_modules()
#ifdef IOS
#import "../iOS/views.h"
static const void* const associated_string_key = &associated_string_key;
// Build a string with a second associated string
static NSString* build_string_pair(NSString* stringA, NSString* stringB)
{
NSString* string_pair = [NSString stringWithString:stringA];
objc_setAssociatedObject(string_pair, "OTHER", stringB, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
objc_setAssociatedObject(string_pair, associated_string_key, stringB, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
return string_pair;
}
@ -147,23 +149,25 @@ static NSString* build_string_pair(NSString* stringA, NSString* stringB)
if (indexPath.section == _firmwareSectionIndex)
{
NSString* item = (NSString*)[self itemForIndexPath:indexPath];
apple_display_alert(objc_getAssociatedObject(item, "OTHER"), item);
apple_display_alert(objc_getAssociatedObject(item, associated_string_key), item);
}
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell* cell = [self.tableView dequeueReusableCellWithIdentifier:@"datacell"];
static NSString* const cell_id = @"datacell";
UITableViewCell* cell = [self.tableView dequeueReusableCellWithIdentifier:cell_id];
if (!cell)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"datacell"];
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cell_id];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.detailTextLabel.adjustsFontSizeToFitWidth = YES;
}
NSString* item = (NSString*)[self itemForIndexPath:indexPath];
NSString* value = (NSString*)objc_getAssociatedObject(item, "OTHER");
NSString* value = (NSString*)objc_getAssociatedObject(item, associated_string_key);
cell.textLabel.text = item;
cell.detailTextLabel.text = value;

View File

@ -69,8 +69,10 @@ void ios_add_log_message(const char* format, ...)
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell* cell = [self.tableView dequeueReusableCellWithIdentifier:@"message"];
cell = cell ? cell : [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"message"];
static NSString* const cell_id = @"message";
UITableViewCell* cell = [self.tableView dequeueReusableCellWithIdentifier:cell_id];
cell = cell ? cell : [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cell_id];
pthread_mutex_lock(&g_lock);
cell.textLabel.text = g_messages[indexPath.row];

View File

@ -296,7 +296,7 @@ static void file_action(enum file_action action, NSString* source, NSString* tar
- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
static NSString* const cell_id;
static NSString* const cell_id = @"module";
UITableViewCell* cell = nil;
if ([self getCellFor:cell_id withStyle:UITableViewCellStyleDefault result:&cell])

View File

@ -36,13 +36,13 @@
- (void)refreshSystemConfig;
@property (strong, nonatomic) NSString* configDirectory; // e.g. /var/mobile/Documents/.RetroArch
@property (strong, nonatomic) NSString* globalConfigFile; // e.g. /var/mobile/Documents/.RetroArch/retroarch.cfg
@property (strong, nonatomic) NSString* coreDirectory; // e.g. /Applications/RetroArch.app/modules
@property (nonatomic) NSString* configDirectory; // e.g. /var/mobile/Documents/.RetroArch
@property (nonatomic) NSString* globalConfigFile; // e.g. /var/mobile/Documents/.RetroArch/retroarch.cfg
@property (nonatomic) NSString* coreDirectory; // e.g. /Applications/RetroArch.app/modules
@property (strong, nonatomic) NSString* documentsDirectory; // e.g. /var/mobile/Documents
@property (strong, nonatomic) NSString* systemDirectory; // e.g. /var/mobile/Documents/.RetroArch
@property (strong, nonatomic) NSString* systemConfigPath; // e.g. /var/mobile/Documents/.RetroArch/frontend.cfg
@property (nonatomic) NSString* documentsDirectory; // e.g. /var/mobile/Documents
@property (nonatomic) NSString* systemDirectory; // e.g. /var/mobile/Documents/.RetroArch
@property (nonatomic) NSString* systemConfigPath; // e.g. /var/mobile/Documents/.RetroArch/frontend.cfg
@end
@ -50,4 +50,4 @@
void ios_set_bluetooth_mode(NSString* mode);
bool is_ios_7();
#endif
#endif

View File

@ -209,7 +209,7 @@ static void handle_touch_event(NSArray* touches)
- (bool)directoryList:(id)list itemWasSelected:(RADirectoryItem*)path
{
if(path.isDirectory)
[[RetroArch_iOS get] pushViewController:[[RADirectoryList alloc] initWithPath:path.path delegate:self] animated:YES];
[self pushViewController:[[RADirectoryList alloc] initWithPath:path.path delegate:self] animated:YES];
else
{
_path = path.path;
@ -218,7 +218,7 @@ static void handle_touch_event(NSArray* touches)
apple_display_alert(@"The directory containing the selected file has limited permissions. This may "
"prevent zipped games from loading, and will cause some cores to not function.", 0);
[[RetroArch_iOS get] pushViewController:[[RAModuleList alloc] initWithGame:path.path delegate:self] animated:YES];
[self pushViewController:[[RAModuleList alloc] initWithGame:path.path delegate:self] animated:YES];
}
return true;

View File

@ -21,6 +21,10 @@
#include "bluetooth/btdynamic.h"
#include "bluetooth/btpad.h"
static const void* const associated_userdata_key = &associated_userdata_key;
static const void* const associated_module_key = &associated_module_key;
static const void* const associated_setting_key = &associated_setting_key;
enum SettingTypes
{
BooleanSetting, ButtonSetting, EnumerationSetting, FileListSetting,
@ -209,7 +213,7 @@ static RASettingData* custom_action(NSString* action, NSString* value, id data,
result->reload = reload_func;
if (data != nil)
objc_setAssociatedObject(result, "USERDATA", data, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
objc_setAssociatedObject(result, associated_userdata_key, data, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
return result;
}
@ -377,7 +381,7 @@ static NSArray* build_input_port_group(config_file_t* config, uint32_t player)
- (void)handleCustomAction:(RASettingData*)setting
{
if ([@"Core Info" isEqualToString:setting->label])
[[RetroArch_iOS get] pushViewController:[[RAModuleInfoList alloc] initWithModuleInfo:_module] animated:YES];
[self.navigationController pushViewController:[[RAModuleInfoList alloc] initWithModuleInfo:_module] animated:YES];
else if([@"Delete Custom Config" isEqualToString:setting->label])
{
[_module deleteCustomConfig];
@ -476,14 +480,14 @@ static void bluetooth_option_changed(RASettingData* setting)
- (void)handleCustomAction:(RASettingData*)setting
{
if ([@"Diagnostic Log" isEqualToString:setting->label])
[[RetroArch_iOS get] pushViewController:[RALogView new] animated:YES];
[self.navigationController pushViewController:[RALogView new] animated:YES];
else if ([@"Enable BTstack" isEqualToString:setting->label])
btstack_set_poweron([setting->value isEqualToString:@"true"]);
else if([@"Global Core Config" isEqualToString:setting->label])
[RetroArch_iOS.get pushViewController:[[RASettingsList alloc] initWithModule:nil] animated:YES];
[self.navigationController pushViewController:[[RASettingsList alloc] initWithModule:nil] animated:YES];
else
{
RAModuleInfo* data = (RAModuleInfo*)objc_getAssociatedObject(setting, "USERDATA");
RAModuleInfo* data = (RAModuleInfo*)objc_getAssociatedObject(setting, associated_userdata_key);
if (data)
{
if (!data.hasCustomConfig)
@ -494,18 +498,18 @@ static void bluetooth_option_changed(RASettingData* setting)
delegate:self
cancelButtonTitle:@"No"
otherButtonTitles:@"Yes", nil];
objc_setAssociatedObject(alert, "MODULE", data, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
objc_setAssociatedObject(alert, associated_module_key, data, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
[alert show];
}
else
[RetroArch_iOS.get pushViewController:[[RASettingsList alloc] initWithModule:data] animated:YES];
[self.navigationController pushViewController:[[RASettingsList alloc] initWithModule:data] animated:YES];
}
}
}
- (void)alertView:(UIAlertView*)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
{
RAModuleInfo* data = (RAModuleInfo*)objc_getAssociatedObject(alertView, "MODULE");
RAModuleInfo* data = (RAModuleInfo*)objc_getAssociatedObject(alertView, associated_module_key);
if (data)
{
@ -515,7 +519,7 @@ static void bluetooth_option_changed(RASettingData* setting)
[self.tableView reloadData];
}
[RetroArch_iOS.get pushViewController:[[RASettingsList alloc] initWithModule:data] animated:YES];
[self.navigationController pushViewController:[[RASettingsList alloc] initWithModule:data] animated:YES];
}
}
@ -614,7 +618,7 @@ static void bluetooth_option_changed(RASettingData* setting)
case EnumerationSetting:
case FileListSetting:
case AspectSetting:
[[RetroArch_iOS get] pushViewController:[[RASettingEnumerationList alloc] initWithSetting:setting fromTable:(UITableView*)self.view] animated:YES];
[self.navigationController pushViewController:[[RASettingEnumerationList alloc] initWithSetting:setting fromTable:(UITableView*)self.view] animated:YES];
break;
case ButtonSetting:
@ -622,7 +626,7 @@ static void bluetooth_option_changed(RASettingData* setting)
break;
case GroupSetting:
[[RetroArch_iOS get] pushViewController:[[RASettingsSubList alloc] initWithSettings:setting->subValues title:setting->label] animated:YES];
[self.navigationController pushViewController:[[RASettingsSubList alloc] initWithSettings:setting->subValues title:setting->label] animated:YES];
break;
default:
@ -634,7 +638,7 @@ static void bluetooth_option_changed(RASettingData* setting)
- (void)handleBooleanSwitch:(UISwitch*)swt
{
RASettingData* setting = objc_getAssociatedObject(swt, "SETTING");
RASettingData* setting = objc_getAssociatedObject(swt, associated_setting_key);
[setting setValue:swt.on ? @"true" : @"false"];
[self handleCustomAction:setting];
@ -642,7 +646,7 @@ static void bluetooth_option_changed(RASettingData* setting)
- (void)handleSlider:(UISlider*)sld
{
RASettingData* setting = objc_getAssociatedObject(sld, "SETTING");
RASettingData* setting = objc_getAssociatedObject(sld, associated_setting_key);
[setting setValue:[NSString stringWithFormat:@"%f", sld.value]];
[self handleCustomAction:setting];
@ -658,11 +662,12 @@ static void bluetooth_option_changed(RASettingData* setting)
{
case BooleanSetting:
{
cell = [self.tableView dequeueReusableCellWithIdentifier:@"boolean"];
static NSString* const cell_id = @"boolean";
cell = [self.tableView dequeueReusableCellWithIdentifier:cell_id];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"boolean"];
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cell_id];
UISwitch* accessory = [[UISwitch alloc] init];
[accessory addTarget:self action:@selector(handleBooleanSwitch:) forControlEvents:UIControlEventValueChanged];
@ -675,18 +680,19 @@ static void bluetooth_option_changed(RASettingData* setting)
UISwitch* swt = (UISwitch*)cell.accessoryView;
swt.on = [setting->value isEqualToString:@"true"];
objc_setAssociatedObject(swt, "SETTING", setting, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
objc_setAssociatedObject(swt, associated_setting_key, setting, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
return cell;
}
case RangeSetting:
{
cell = [self.tableView dequeueReusableCellWithIdentifier:@"range"];
static NSString* const cell_id = @"range";
cell = [self.tableView dequeueReusableCellWithIdentifier:cell_id];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"range"];
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cell_id];
UISlider* accessory = [UISlider new];
[accessory addTarget:self action:@selector(handleSlider:) forControlEvents:UIControlEventValueChanged];
@ -702,7 +708,7 @@ static void bluetooth_option_changed(RASettingData* setting)
sld.minimumValue = setting->rangeMin;
sld.maximumValue = setting->rangeMax;
sld.value = [setting->value doubleValue];
objc_setAssociatedObject(sld, "SETTING", setting, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
objc_setAssociatedObject(sld, associated_setting_key, setting, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
return cell;
}
@ -710,16 +716,17 @@ static void bluetooth_option_changed(RASettingData* setting)
default:
{
cell = [self.tableView dequeueReusableCellWithIdentifier:@"default"];
static NSString* const cell_id = @"default";
cell = [self.tableView dequeueReusableCellWithIdentifier:cell_id];
if (!cell)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"default"];
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cell_id];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
if (setting->reload)
setting->reload(setting, objc_getAssociatedObject(setting, "USERDATA"));
setting->reload(setting, objc_getAssociatedObject(setting, associated_userdata_key));
cell.textLabel.text = setting->label;
@ -771,8 +778,10 @@ static void bluetooth_option_changed(RASettingData* setting)
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell* cell = [self.tableView dequeueReusableCellWithIdentifier:@"option"];
cell = cell ? cell : [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"option"];
static NSString* const cell_id = @"option";
UITableViewCell* cell = [self.tableView dequeueReusableCellWithIdentifier:cell_id];
cell = cell ? cell : [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cell_id];
if (indexPath.section == _mainSection)
cell.textLabel.text = [_value labelForEnumerationIndex:indexPath.row];
@ -787,7 +796,7 @@ static void bluetooth_option_changed(RASettingData* setting)
[_value setValue: (indexPath.section == _mainSection) ? [_value valueForEnumerationIndex:indexPath.row] : @""];
[_view reloadData];
[[RetroArch_iOS get] popViewControllerAnimated:YES];
[self.navigationController popViewControllerAnimated:YES];
}
@end

View File

@ -24,8 +24,8 @@
// utility.m
@interface RATableViewController : UITableViewController
@property NSMutableArray* sections;
@property BOOL hidesHeaders;
@property (nonatomic) NSMutableArray* sections;
@property (nonatomic) BOOL hidesHeaders;
- (id)initWithStyle:(UITableViewStyle)style;
- (bool)getCellFor:(NSString*)reuseID withStyle:(UITableViewCellStyle)style result:(UITableViewCell**)output;
@ -35,8 +35,8 @@
// browser.m
@interface RADirectoryItem : NSObject
@property (strong) NSString* path;
@property bool isDirectory;
@property (nonatomic) NSString* path;
@property (nonatomic) bool isDirectory;
@end
// browser.m