Updated the iOS Objective-C code to use NSDictionary/NSArray/NSNumber literals and subscripting, for improved code clarity. iOS-improvements
authorAlex Szpakowski <slime73@gmail.com>
Wed, 23 Jul 2014 01:28:24 -0300
branchiOS-improvements
changeset 9499 6fe9b44b2d84
parent 9498 d02c27e3f698
child 9500 cbf5c5ecf5ac
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
src/video/uikit/SDL_uikitopenglview.m
src/video/uikit/SDL_uikitvideo.h
src/video/uikit/SDL_uikitview.h
src/video/uikit/SDL_uikitview.m
src/video/uikit/SDL_uikitviewcontroller.m
--- a/src/video/uikit/SDL_uikitmessagebox.m	Tue Jul 22 20:06:13 2014 -0300
+++ b/src/video/uikit/SDL_uikitmessagebox.m	Wed Jul 23 01:28:24 2014 -0300
@@ -53,7 +53,7 @@
     return self;
 }
 
-- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex;
+- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
 {
     *clickedButtonIndex = (int)buttonIndex;
 }
@@ -77,8 +77,8 @@
     @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) {
--- a/src/video/uikit/SDL_uikitopenglview.m	Tue Jul 22 20:06:13 2014 -0300
+++ b/src/video/uikit/SDL_uikitopenglview.m	Wed Jul 23 01:28:24 2014 -0300
@@ -94,10 +94,10 @@
         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;
--- a/src/video/uikit/SDL_uikitvideo.h	Tue Jul 22 20:06:13 2014 -0300
+++ b/src/video/uikit/SDL_uikitvideo.h	Wed Jul 23 01:28:24 2014 -0300
@@ -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 */
 
--- a/src/video/uikit/SDL_uikitview.h	Tue Jul 22 20:06:13 2014 -0300
+++ b/src/video/uikit/SDL_uikitview.h	Wed Jul 23 01:28:24 2014 -0300
@@ -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);
--- a/src/video/uikit/SDL_uikitview.m	Tue Jul 22 20:06:13 2014 -0300
+++ b/src/video/uikit/SDL_uikitview.m	Wed Jul 23 01:28:24 2014 -0300
@@ -395,7 +395,7 @@
                          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) {
--- a/src/video/uikit/SDL_uikitviewcontroller.m	Tue Jul 22 20:06:13 2014 -0300
+++ b/src/video/uikit/SDL_uikitviewcontroller.m	Wed Jul 23 01:28:24 2014 -0300
@@ -70,9 +70,7 @@
     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"]) {