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 94996fe9b44b2d84
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
     1.1 --- a/src/video/uikit/SDL_uikitmessagebox.m	Tue Jul 22 20:06:13 2014 -0300
     1.2 +++ b/src/video/uikit/SDL_uikitmessagebox.m	Wed Jul 23 01:28:24 2014 -0300
     1.3 @@ -53,7 +53,7 @@
     1.4      return self;
     1.5  }
     1.6  
     1.7 -- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex;
     1.8 +- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
     1.9  {
    1.10      *clickedButtonIndex = (int)buttonIndex;
    1.11  }
    1.12 @@ -77,8 +77,8 @@
    1.13      @autoreleasepool {
    1.14          UIAlertView* alert = [[UIAlertView alloc] init];
    1.15  
    1.16 -        alert.title = [NSString stringWithUTF8String:messageboxdata->title];
    1.17 -        alert.message = [NSString stringWithUTF8String:messageboxdata->message];
    1.18 +        alert.title = @(messageboxdata->title);
    1.19 +        alert.message = @(messageboxdata->message);
    1.20          alert.delegate = [[UIKit_UIAlertViewDelegate alloc] initWithButtonIndex:&clicked];
    1.21  
    1.22          for (i = 0; i < messageboxdata->numbuttons; ++i) {
     2.1 --- a/src/video/uikit/SDL_uikitopenglview.m	Tue Jul 22 20:06:13 2014 -0300
     2.2 +++ b/src/video/uikit/SDL_uikitopenglview.m	Wed Jul 23 01:28:24 2014 -0300
     2.3 @@ -94,10 +94,10 @@
     2.4          CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;
     2.5  
     2.6          eaglLayer.opaque = YES;
     2.7 -        eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
     2.8 -                                        [NSNumber numberWithBool: retained], kEAGLDrawablePropertyRetainedBacking,
     2.9 -                                        colorFormat, kEAGLDrawablePropertyColorFormat,
    2.10 -                                        nil];
    2.11 +        eaglLayer.drawableProperties = @{
    2.12 +            kEAGLDrawablePropertyRetainedBacking: @(retained),
    2.13 +            kEAGLDrawablePropertyColorFormat: colorFormat
    2.14 +        };
    2.15  
    2.16          /* Set the appropriate scale (for retina display support) */
    2.17          self.contentScaleFactor = scale;
     3.1 --- a/src/video/uikit/SDL_uikitvideo.h	Tue Jul 22 20:06:13 2014 -0300
     3.2 +++ b/src/video/uikit/SDL_uikitvideo.h	Wed Jul 23 01:28:24 2014 -0300
     3.3 @@ -25,20 +25,6 @@
     3.4  
     3.5  #include "../SDL_sysvideo.h"
     3.6  
     3.7 -#ifndef __IPHONE_6_0
     3.8 -/* 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 */
     3.9 -enum UIInterfaceOrientationMask
    3.10 -{
    3.11 -    UIInterfaceOrientationMaskPortrait = (1 << UIInterfaceOrientationPortrait),
    3.12 -    UIInterfaceOrientationMaskLandscapeLeft = (1 << UIInterfaceOrientationLandscapeLeft),
    3.13 -    UIInterfaceOrientationMaskLandscapeRight = (1 << UIInterfaceOrientationLandscapeRight),
    3.14 -    UIInterfaceOrientationMaskPortraitUpsideDown = (1 << UIInterfaceOrientationPortraitUpsideDown),
    3.15 -    UIInterfaceOrientationMaskLandscape = (UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight),
    3.16 -    UIInterfaceOrientationMaskAll = (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortraitUpsideDown),
    3.17 -    UIInterfaceOrientationMaskAllButUpsideDown = (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight),
    3.18 -};
    3.19 -#endif /* !__IPHONE_6_0 */
    3.20 -
    3.21  
    3.22  #endif /* _SDL_uikitvideo_h */
    3.23  
     4.1 --- a/src/video/uikit/SDL_uikitview.h	Tue Jul 22 20:06:13 2014 -0300
     4.2 +++ b/src/video/uikit/SDL_uikitview.h	Wed Jul 23 01:28:24 2014 -0300
     4.3 @@ -61,9 +61,9 @@
     4.4  - (void)showKeyboard;
     4.5  - (void)hideKeyboard;
     4.6  - (void)initializeKeyboard;
     4.7 -@property (readonly) BOOL keyboardVisible;
     4.8 -@property (nonatomic,assign) SDL_Rect textInputRect;
     4.9 -@property (nonatomic,assign) int keyboardHeight;
    4.10 +@property (nonatomic, readonly) BOOL keyboardVisible;
    4.11 +@property (nonatomic, assign) SDL_Rect textInputRect;
    4.12 +@property (nonatomic, assign) int keyboardHeight;
    4.13  
    4.14  SDL_bool UIKit_HasScreenKeyboardSupport(_THIS);
    4.15  void UIKit_ShowScreenKeyboard(_THIS, SDL_Window *window);
     5.1 --- a/src/video/uikit/SDL_uikitview.m	Tue Jul 22 20:06:13 2014 -0300
     5.2 +++ b/src/video/uikit/SDL_uikitview.m	Wed Jul 23 01:28:24 2014 -0300
     5.3 @@ -395,7 +395,7 @@
     5.4                           queue:queue
     5.5                      usingBlock:^(NSNotification *notification) {
     5.6                          int height = 0;
     5.7 -                        CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
     5.8 +                        CGSize keyboardSize = [[notification userInfo][UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
     5.9                          height = keyboardSize.height;
    5.10                          UIInterfaceOrientation ui_orient = [[UIApplication sharedApplication] statusBarOrientation];
    5.11                          if (ui_orient == UIInterfaceOrientationLandscapeRight || ui_orient == UIInterfaceOrientationLandscapeLeft) {
     6.1 --- a/src/video/uikit/SDL_uikitviewcontroller.m	Tue Jul 22 20:06:13 2014 -0300
     6.2 +++ b/src/video/uikit/SDL_uikitviewcontroller.m	Wed Jul 23 01:28:24 2014 -0300
     6.3 @@ -70,9 +70,7 @@
     6.4      const char *orientationsHint = SDL_GetHint(SDL_HINT_ORIENTATIONS);
     6.5  
     6.6      if (orientationsHint != NULL) {
     6.7 -        NSString *orientationsString = [NSString stringWithCString:orientationsHint
     6.8 -                                                          encoding:NSUTF8StringEncoding];
     6.9 -        NSArray *orientations = [orientationsString componentsSeparatedByCharactersInSet:
    6.10 +        NSArray *orientations = [@(orientationsHint) componentsSeparatedByCharactersInSet:
    6.11                                   [NSCharacterSet characterSetWithCharactersInString:@" "]];
    6.12  
    6.13          if ([orientations containsObject:@"LandscapeLeft"]) {