From 967549c9adbc37544fe0d43e3343b225f9d1d602 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Wed, 23 Jul 2014 01:28:24 -0300 Subject: [PATCH] Updated the iOS Objective-C code to use NSDictionary/NSArray/NSNumber literals and subscripting, for improved code clarity. This requires at least Xcode 4.5 and the iOS 6 SDK to build, but it doesn't change the minimum supported runtime version (iOS 5.1). Less than 2% of iOS users are running iOS 5, so I hope developers aren't trying to build SDL using an SDK which doesn't support iOS 6/7... --- src/video/uikit/SDL_uikitmessagebox.m | 6 +++--- src/video/uikit/SDL_uikitopenglview.m | 8 ++++---- src/video/uikit/SDL_uikitvideo.h | 14 -------------- src/video/uikit/SDL_uikitview.h | 6 +++--- src/video/uikit/SDL_uikitview.m | 2 +- src/video/uikit/SDL_uikitviewcontroller.m | 4 +--- 6 files changed, 12 insertions(+), 28 deletions(-) diff --git a/src/video/uikit/SDL_uikitmessagebox.m b/src/video/uikit/SDL_uikitmessagebox.m index 78f84e3eb4761..0fa4bda2eedbd 100644 --- a/src/video/uikit/SDL_uikitmessagebox.m +++ b/src/video/uikit/SDL_uikitmessagebox.m @@ -53,7 +53,7 @@ - (id)initWithButtonIndex:(int *)buttonIndex return self; } -- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex; +- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex { *clickedButtonIndex = (int)buttonIndex; } @@ -77,8 +77,8 @@ - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger) @autoreleasepool { UIAlertView* alert = [[UIAlertView alloc] init]; - alert.title = [NSString stringWithUTF8String:messageboxdata->title]; - alert.message = [NSString stringWithUTF8String:messageboxdata->message]; + alert.title = @(messageboxdata->title); + alert.message = @(messageboxdata->message); alert.delegate = [[UIKit_UIAlertViewDelegate alloc] initWithButtonIndex:&clicked]; for (i = 0; i < messageboxdata->numbuttons; ++i) { diff --git a/src/video/uikit/SDL_uikitopenglview.m b/src/video/uikit/SDL_uikitopenglview.m index b5c16eab413a4..1f33f529d0138 100644 --- a/src/video/uikit/SDL_uikitopenglview.m +++ b/src/video/uikit/SDL_uikitopenglview.m @@ -94,10 +94,10 @@ - (id)initWithFrame:(CGRect)frame CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer; eaglLayer.opaque = YES; - eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys: - [NSNumber numberWithBool: retained], kEAGLDrawablePropertyRetainedBacking, - colorFormat, kEAGLDrawablePropertyColorFormat, - nil]; + eaglLayer.drawableProperties = @{ + kEAGLDrawablePropertyRetainedBacking: @(retained), + kEAGLDrawablePropertyColorFormat: colorFormat + }; /* Set the appropriate scale (for retina display support) */ self.contentScaleFactor = scale; diff --git a/src/video/uikit/SDL_uikitvideo.h b/src/video/uikit/SDL_uikitvideo.h index ef62982570f53..819f93aff50c5 100644 --- a/src/video/uikit/SDL_uikitvideo.h +++ b/src/video/uikit/SDL_uikitvideo.h @@ -25,20 +25,6 @@ #include "../SDL_sysvideo.h" -#ifndef __IPHONE_6_0 -/* This enum isn't available in older SDKs, but we use it for our own purposes on iOS 5.1 and for the system on iOS 6.0 */ -enum UIInterfaceOrientationMask -{ - UIInterfaceOrientationMaskPortrait = (1 << UIInterfaceOrientationPortrait), - UIInterfaceOrientationMaskLandscapeLeft = (1 << UIInterfaceOrientationLandscapeLeft), - UIInterfaceOrientationMaskLandscapeRight = (1 << UIInterfaceOrientationLandscapeRight), - UIInterfaceOrientationMaskPortraitUpsideDown = (1 << UIInterfaceOrientationPortraitUpsideDown), - UIInterfaceOrientationMaskLandscape = (UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight), - UIInterfaceOrientationMaskAll = (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortraitUpsideDown), - UIInterfaceOrientationMaskAllButUpsideDown = (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight), -}; -#endif /* !__IPHONE_6_0 */ - #endif /* _SDL_uikitvideo_h */ diff --git a/src/video/uikit/SDL_uikitview.h b/src/video/uikit/SDL_uikitview.h index ce616c07eb3b7..8191915b33806 100644 --- a/src/video/uikit/SDL_uikitview.h +++ b/src/video/uikit/SDL_uikitview.h @@ -61,9 +61,9 @@ - (void)showKeyboard; - (void)hideKeyboard; - (void)initializeKeyboard; -@property (readonly) BOOL keyboardVisible; -@property (nonatomic,assign) SDL_Rect textInputRect; -@property (nonatomic,assign) int keyboardHeight; +@property (nonatomic, readonly) BOOL keyboardVisible; +@property (nonatomic, assign) SDL_Rect textInputRect; +@property (nonatomic, assign) int keyboardHeight; SDL_bool UIKit_HasScreenKeyboardSupport(_THIS); void UIKit_ShowScreenKeyboard(_THIS, SDL_Window *window); diff --git a/src/video/uikit/SDL_uikitview.m b/src/video/uikit/SDL_uikitview.m index 7312307f51fea..0f790169d240b 100644 --- a/src/video/uikit/SDL_uikitview.m +++ b/src/video/uikit/SDL_uikitview.m @@ -395,7 +395,7 @@ void _uikit_keyboard_init() { queue:queue usingBlock:^(NSNotification *notification) { int height = 0; - CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size; + CGSize keyboardSize = [[notification userInfo][UIKeyboardFrameBeginUserInfoKey] CGRectValue].size; height = keyboardSize.height; UIInterfaceOrientation ui_orient = [[UIApplication sharedApplication] statusBarOrientation]; if (ui_orient == UIInterfaceOrientationLandscapeRight || ui_orient == UIInterfaceOrientationLandscapeLeft) { diff --git a/src/video/uikit/SDL_uikitviewcontroller.m b/src/video/uikit/SDL_uikitviewcontroller.m index 7fee597eb8f97..d21723bfe6a6f 100644 --- a/src/video/uikit/SDL_uikitviewcontroller.m +++ b/src/video/uikit/SDL_uikitviewcontroller.m @@ -70,9 +70,7 @@ - (NSUInteger)supportedInterfaceOrientations const char *orientationsHint = SDL_GetHint(SDL_HINT_ORIENTATIONS); if (orientationsHint != NULL) { - NSString *orientationsString = [NSString stringWithCString:orientationsHint - encoding:NSUTF8StringEncoding]; - NSArray *orientations = [orientationsString componentsSeparatedByCharactersInSet: + NSArray *orientations = [@(orientationsHint) componentsSeparatedByCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@" "]]; if ([orientations containsObject:@"LandscapeLeft"]) {