Skip to content

Commit 625df26

Browse files
authored
Fix Objective-C/C++ codes to supporting ARC (openframeworks#6889)
#changelog #osx #ios #tvos
1 parent 2840608 commit 625df26

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+375
-459
lines changed

addons/ofxiOS/src/core/ofxiOSAppDelegate.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@
4444
NSInteger currentScreenIndex;
4545
}
4646

47-
@property (nonatomic, retain) UIWindow * window;
48-
@property (nonatomic, retain) UIWindow * externalWindow;
49-
@property (nonatomic, retain) UIViewController * uiViewController;
50-
@property (readonly, assign) NSInteger currentScreenIndex;
47+
@property (nonatomic, strong) UIWindow * window;
48+
@property (nonatomic, strong) UIWindow * externalWindow;
49+
@property (nonatomic, strong) UIViewController * uiViewController;
50+
@property (readonly) NSInteger currentScreenIndex;
5151

5252
- (BOOL)application:(UIApplication*)application
5353
handleOpenURL:(NSURL*)url;

addons/ofxiOS/src/core/ofxiOSAppDelegate.mm

+34-24
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@
2929
*
3030
* ***********************************************************************/
3131

32-
#include "ofxiOSAppDelegate.h"
32+
#import "ofxiOSAppDelegate.h"
3333

3434
#if TARGET_OS_IOS || (TARGET_OS_IPHONE && !TARGET_OS_TV)
3535

36-
#include "ofxiOSViewController.h"
37-
#include "ofxiOSExternalDisplay.h"
36+
#import "ofxiOSViewController.h"
37+
#import "ofxiOSGLKViewController.h"
38+
#import "ofxiOSExternalDisplay.h"
3839
#include "ofxiOSExtras.h"
3940
#include "ofxiOSAlerts.h"
4041
#include "ofxiOSEAGLView.h"
@@ -45,22 +46,17 @@
4546

4647
@implementation ofxiOSAppDelegate
4748

48-
@synthesize window;
49-
@synthesize externalWindow;
5049
@synthesize currentScreenIndex;
5150

52-
@synthesize uiViewController;
53-
5451
- (void)dealloc {
5552
self.window = nil;
5653
self.externalWindow = nil;
5754
self.uiViewController = nil;
58-
[super dealloc];
5955
}
6056

6157
- (void)applicationDidFinishLaunching:(UIApplication *)application {
6258

63-
self.window = [[[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]] autorelease];
59+
self.window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
6460
[self.window makeKeyAndVisible];
6561

6662
currentScreenIndex = 0;
@@ -145,11 +141,11 @@ - (void)applicationDidFinishLaunching:(UIApplication *)application {
145141
case METAL_KIT:
146142
NSLog(@"No MetalKit yet supported for openFrameworks: Falling back to GLKit");
147143
case GL_KIT:
148-
self.uiViewController = (UIViewController*)[[[ofxiOSGLKViewController alloc] initWithFrame:frame app:(ofxiOSApp *)ofGetAppPtr() sharegroup:nil] autorelease];
144+
self.uiViewController = (UIViewController *)[[ofxiOSGLKViewController alloc] initWithFrame:frame app:(ofxiOSApp *)ofGetAppPtr() sharegroup:nil];
149145
break;
150146
case CORE_ANIMATION:
151147
default:
152-
self.uiViewController = [[[ofxiOSViewController alloc] initWithFrame:frame app:(ofxiOSApp *)ofGetAppPtr() sharegroup:nil] autorelease];
148+
self.uiViewController = [[ofxiOSViewController alloc] initWithFrame:frame app:(ofxiOSApp *)ofGetAppPtr() sharegroup:nil];
153149
break;
154150

155151
}
@@ -172,14 +168,22 @@ - (void)applicationDidFinishLaunching:(UIApplication *)application {
172168
}
173169

174170
if(!bDoesHWOrientation) {
175-
if([self.uiViewController respondsToSelector:@selector(rotateToInterfaceOrientation:animated:)]) {
176-
[self.uiViewController rotateToInterfaceOrientation:UIInterfaceOrientationPortrait animated:false];
177-
}
171+
if([self.uiViewController isKindOfClass:ofxiOSViewController.class]) {
172+
ofxiOSViewController *controller = (ofxiOSViewController*)self.uiViewController;
173+
[controller rotateToInterfaceOrientation:UIInterfaceOrientationPortrait animated:false];
174+
} else if([self.uiViewController isKindOfClass:ofxiOSGLKViewController.class]) {
175+
ofxiOSGLKViewController *controller = (ofxiOSGLKViewController *)self.uiViewController;
176+
[controller rotateToInterfaceOrientation:UIInterfaceOrientationPortrait animated:false];
177+
}
178178
} else {
179179
[[UIApplication sharedApplication] setStatusBarOrientation:interfaceOrientation animated:NO];
180-
if([self.uiViewController respondsToSelector:@selector(rotateToInterfaceOrientation:animated:)]) {
181-
[self.uiViewController rotateToInterfaceOrientation:interfaceOrientation animated:false];
182-
}
180+
if([self.uiViewController isKindOfClass:ofxiOSViewController.class]) {
181+
ofxiOSViewController *controller = (ofxiOSViewController*)self.uiViewController;
182+
[controller rotateToInterfaceOrientation:UIInterfaceOrientationPortrait animated:false];
183+
} else if([self.uiViewController isKindOfClass:ofxiOSGLKViewController.class]) {
184+
ofxiOSGLKViewController *controller = (ofxiOSGLKViewController *)self.uiViewController;
185+
[controller rotateToInterfaceOrientation:UIInterfaceOrientationPortrait animated:false];
186+
}
183187
ofSetOrientation(requested);
184188
}
185189

@@ -239,11 +243,17 @@ - (void)receivedRotate:(NSNotification*)notification {
239243
if( [[[UIDevice currentDevice] systemVersion] compare:@"8.0" options:NSNumericSearch] == NSOrderedAscending ) {
240244
//iOS7-
241245
if(deviceOrientation != UIDeviceOrientationUnknown && deviceOrientation != UIDeviceOrientationFaceUp && deviceOrientation != UIDeviceOrientationFaceDown ) {
242-
if([self.uiViewController respondsToSelector:@selector(isReadyToRotate)]) {
243-
if([self.uiViewController isReadyToRotate]) {
244-
ofxiOSAlerts.deviceOrientationChanged( deviceOrientation );
245-
}
246-
}
246+
if([self.uiViewController isKindOfClass:ofxiOSViewController.class]) {
247+
ofxiOSViewController *controller = (ofxiOSViewController*)self.uiViewController;
248+
if([controller isReadyToRotate]) {
249+
ofxiOSAlerts.deviceOrientationChanged( deviceOrientation );
250+
}
251+
} else if([self.uiViewController isKindOfClass:ofxiOSGLKViewController.class]) {
252+
ofxiOSGLKViewController *controller = (ofxiOSGLKViewController *)self.uiViewController;
253+
if([controller isReadyToRotate]) {
254+
ofxiOSAlerts.deviceOrientationChanged( deviceOrientation );
255+
}
256+
}
247257
}
248258
}else {
249259
ofxiOSAlerts.deviceOrientationChanged( deviceOrientation );
@@ -293,7 +303,7 @@ - (BOOL)createExternalWindowWithPreferredMode {
293303
externalScreenFrame = CGRectZero;
294304
externalScreenFrame.size = CGSizeMake(w, h);
295305

296-
self.externalWindow = [[[UIWindow alloc] initWithFrame:externalScreenFrame] autorelease];
306+
self.externalWindow = [[UIWindow alloc] initWithFrame:externalScreenFrame];
297307
self.externalWindow.screen = externalScreen;
298308
self.externalWindow.clipsToBounds = YES;
299309
self.externalWindow.hidden = NO;
@@ -331,7 +341,7 @@ - (BOOL)createExternalWindowWithScreenModeIndex:(NSInteger)screenModeIndex {
331341
externalScreenFrame = CGRectZero;
332342
externalScreenFrame.size = CGSizeMake(w, h);
333343

334-
self.externalWindow = [[[UIWindow alloc] initWithFrame:externalScreenFrame] autorelease];
344+
self.externalWindow = [[UIWindow alloc] initWithFrame:externalScreenFrame];
335345
self.externalWindow.screen = externalScreen;
336346
self.externalWindow.clipsToBounds = YES;
337347
self.externalWindow.hidden = NO;

addons/ofxiOS/src/core/ofxiOSEAGLView.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class ofAppiOSWindow;
1717
@interface ofxiOSEAGLView : EAGLView {
1818

1919
@protected
20-
NSMutableDictionary * activeTouches;
20+
NSMutableDictionary<NSValue *, NSNumber *> *activeTouches;
2121
glm::vec2 * screenSize; // because glm::vec2 is forward declared,
2222
glm::vec2 * windowSize; // these values have to be pointers.
2323
glm::vec2 * windowPos;
@@ -29,8 +29,8 @@ class ofAppiOSWindow;
2929

3030
+ (ofxiOSEAGLView *) getInstance;
3131

32-
- (id)initWithFrame:(CGRect)frame andApp:(ofxiOSApp *)app;
33-
- (id)initWithFrame:(CGRect)frame andApp:(ofxiOSApp *)app sharegroup:(EAGLSharegroup *)sharegroup;
32+
- (instancetype)initWithFrame:(CGRect)frame andApp:(ofxiOSApp *)app;
33+
- (instancetype)initWithFrame:(CGRect)frame andApp:(ofxiOSApp *)app sharegroup:(EAGLSharegroup *)sharegroup;
3434
- (void)setup;
3535
- (void)updateDimensions;
3636
- (void)destroy;

addons/ofxiOS/src/core/ofxiOSEAGLView.mm

+12-15
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,11 @@ + (ofxiOSEAGLView *) getInstance {
3434
return _instanceRef;
3535
}
3636

37-
- (id)initWithFrame:(CGRect)frame andApp:(ofxiOSApp *)appPtr {
38-
[self initWithFrame:frame andApp:appPtr sharegroup:nil];
39-
return self;
37+
- (instancetype)initWithFrame:(CGRect)frame andApp:(ofxiOSApp *)appPtr {
38+
return [self initWithFrame:frame andApp:appPtr sharegroup:nil];
4039
}
4140

42-
- (id)initWithFrame:(CGRect)frame andApp:(ofxiOSApp *)appPtr sharegroup:(EAGLSharegroup *)sharegroup {
41+
- (instancetype)initWithFrame:(CGRect)frame andApp:(ofxiOSApp *)appPtr sharegroup:(EAGLSharegroup *)sharegroup {
4342

4443
window = dynamic_pointer_cast<ofAppiOSWindow>(ofGetMainLoop()->getCurrentWindow());
4544

@@ -128,8 +127,7 @@ - (void)destroy {
128127
app = NULL;
129128
window = NULL;
130129

131-
[activeTouches release];
132-
130+
activeTouches = nil;
133131
delete screenSize;
134132
screenSize = NULL;
135133
delete windowSize;
@@ -146,7 +144,6 @@ - (void)destroy {
146144

147145
- (void)dealloc {
148146
[self destroy];
149-
[super dealloc];
150147
}
151148

152149
- (void)layoutSubviews {
@@ -248,7 +245,7 @@ -(void) resetTouches {
248245
[activeTouches removeAllObjects];
249246
}
250247

251-
- (void)touchesBegan:(NSSet *)touches
248+
- (void)touchesBegan:(NSSet<UITouch *> *)touches
252249
withEvent:(UIEvent *)event{
253250

254251
if(!bInit || !bSetup) {
@@ -259,12 +256,12 @@ - (void)touchesBegan:(NSSet *)touches
259256

260257
for(UITouch *touch in touches) {
261258
int touchIndex = 0;
262-
while([[activeTouches allValues] containsObject:[NSNumber numberWithInt:touchIndex]]){
259+
while([[activeTouches allValues] containsObject:@(touchIndex)]){
263260
touchIndex++;
264261
}
265262

266-
[activeTouches setObject:[NSNumber numberWithInt:touchIndex] forKey:[NSValue valueWithPointer:touch]];
267-
263+
[activeTouches setObject:[NSNumber numberWithInt:touchIndex]
264+
forKey:[NSValue valueWithPointer:(__bridge void *)touch]];
268265
CGPoint touchPoint = [touch locationInView:self];
269266

270267
touchPoint.x *= scaleFactor; // this has to be done because retina still returns points in 320x240 but with high percision
@@ -300,7 +297,7 @@ - (void)touchesMoved:(NSSet *)touches
300297
}
301298

302299
for(UITouch *touch in touches){
303-
int touchIndex = [[activeTouches objectForKey:[NSValue valueWithPointer:touch]] intValue];
300+
int touchIndex = [[activeTouches objectForKey:[NSValue valueWithPointer:(__bridge void *)touch]] intValue];
304301

305302
CGPoint touchPoint = [touch locationInView:self];
306303

@@ -332,9 +329,9 @@ - (void)touchesEnded:(NSSet *)touches
332329
}
333330

334331
for(UITouch *touch in touches){
335-
int touchIndex = [[activeTouches objectForKey:[NSValue valueWithPointer:touch]] intValue];
332+
int touchIndex = [[activeTouches objectForKey:[NSValue valueWithPointer:(__bridge void *)touch]] intValue];
336333

337-
[activeTouches removeObjectForKey:[NSValue valueWithPointer:touch]];
334+
[activeTouches removeObjectForKey:[NSValue valueWithPointer:(__bridge void *)touch]];
338335

339336
CGPoint touchPoint = [touch locationInView:self];
340337

@@ -367,7 +364,7 @@ - (void)touchesCancelled:(NSSet *)touches
367364
}
368365

369366
for(UITouch *touch in touches){
370-
int touchIndex = [[activeTouches objectForKey:[NSValue valueWithPointer:touch]] intValue];
367+
int touchIndex = [[activeTouches objectForKey:[NSValue valueWithPointer:(__bridge void *)touch]] intValue];
371368

372369
CGPoint touchPoint = [touch locationInView:self];
373370

addons/ofxiOS/src/core/ofxiOSGLKView.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class ofAppiOSWindow;
1818
@interface ofxiOSGLKView : EAGLKView {
1919

2020
@protected
21-
NSMutableDictionary * activeTouches;
21+
NSMutableDictionary<NSValue *, NSNumber *> * activeTouches;
2222
glm::vec2 * screenSize; // because glm::vec2 is forward declared,
2323
glm::vec2 * windowSize; // these values have to be pointers.
2424
glm::vec2 * windowPos;
@@ -30,11 +30,11 @@ class ofAppiOSWindow;
3030

3131
+ (ofxiOSGLKView *) getInstance;
3232

33-
- (id)initWithFrame:(CGRect)frame
34-
andApp:(ofxiOSApp *)app;
35-
- (id)initWithFrame:(CGRect)frame
36-
andApp:(ofxiOSApp *)app
37-
sharegroup:(EAGLSharegroup *)sharegroup;
33+
- (instancetype)initWithFrame:(CGRect)frame
34+
andApp:(ofxiOSApp *)app;
35+
- (instancetype)initWithFrame:(CGRect)frame
36+
andApp:(ofxiOSApp *)app
37+
sharegroup:(EAGLSharegroup *)sharegroup;
3838
- (void)setup;
3939
- (void)update;
4040
- (void)draw;

addons/ofxiOS/src/core/ofxiOSGLKView.mm

+8-10
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ + (ofxiOSGLKView *) getInstance {
3434
return _instanceRef;
3535
}
3636

37-
- (id)initWithFrame:(CGRect)frame andApp:(ofxiOSApp *)appPtr {
37+
- (instancetype)initWithFrame:(CGRect)frame andApp:(ofxiOSApp *)appPtr {
3838
return [self initWithFrame:frame andApp:appPtr sharegroup:nil];
3939
}
4040

41-
- (id)initWithFrame:(CGRect)frame andApp:(ofxiOSApp *)appPtr sharegroup:(EAGLSharegroup *)sharegroup{
41+
- (instancetype)initWithFrame:(CGRect)frame andApp:(ofxiOSApp *)appPtr sharegroup:(EAGLSharegroup *)sharegroup{
4242

4343
window = dynamic_pointer_cast<ofAppiOSWindow>(ofGetMainLoop()->getCurrentWindow());
4444

@@ -128,8 +128,7 @@ - (void)destroy {
128128
app = NULL;
129129
window = NULL;
130130

131-
[activeTouches release];
132-
131+
activeTouches = nil;
133132
delete screenSize;
134133
screenSize = NULL;
135134
delete windowSize;
@@ -146,7 +145,6 @@ - (void)destroy {
146145

147146
- (void)dealloc {
148147
[self destroy];
149-
[super dealloc];
150148
}
151149

152150
- (void)layoutSubviews {
@@ -270,7 +268,7 @@ - (void)touchesBegan:(NSSet *)touches
270268
touchIndex++;
271269
}
272270

273-
[activeTouches setObject:[NSNumber numberWithInt:touchIndex] forKey:[NSValue valueWithPointer:touch]];
271+
[activeTouches setObject:@(touchIndex) forKey:[NSValue valueWithPointer:(__bridge void *)touch]];
274272

275273
CGPoint touchPoint = [touch locationInView:self];
276274

@@ -307,7 +305,7 @@ - (void)touchesMoved:(NSSet *)touches
307305
}
308306

309307
for(UITouch *touch in touches){
310-
int touchIndex = [[activeTouches objectForKey:[NSValue valueWithPointer:touch]] intValue];
308+
int touchIndex = [[activeTouches objectForKey:[NSValue valueWithPointer:(__bridge void *)touch]] intValue];
311309

312310
CGPoint touchPoint = [touch locationInView:self];
313311

@@ -339,9 +337,9 @@ - (void)touchesEnded:(NSSet *)touches
339337
}
340338

341339
for(UITouch *touch in touches){
342-
int touchIndex = [[activeTouches objectForKey:[NSValue valueWithPointer:touch]] intValue];
340+
int touchIndex = [[activeTouches objectForKey:[NSValue valueWithPointer:(__bridge void *)touch]] intValue];
343341

344-
[activeTouches removeObjectForKey:[NSValue valueWithPointer:touch]];
342+
[activeTouches removeObjectForKey:[NSValue valueWithPointer:(__bridge void *)touch]];
345343

346344
CGPoint touchPoint = [touch locationInView:self];
347345

@@ -374,7 +372,7 @@ - (void)touchesCancelled:(NSSet *)touches
374372
}
375373

376374
for(UITouch *touch in touches){
377-
int touchIndex = [[activeTouches objectForKey:[NSValue valueWithPointer:touch]] intValue];
375+
int touchIndex = [[activeTouches objectForKey:[NSValue valueWithPointer:(__bridge void *)touch]] intValue];
378376

379377
CGPoint touchPoint = [touch locationInView:self];
380378

addons/ofxiOS/src/core/ofxiOSGLKViewController.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ class ofxiOSApp;
2121

2222
@interface ofxiOSGLKViewController : GLKViewController
2323

24-
@property (nonatomic, retain) ofxiOSGLKView * glView;
24+
@property (nonatomic, strong) ofxiOSGLKView * glView;
2525

26-
- (id)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app;
27-
- (id)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app sharegroup:(EAGLSharegroup *)sharegroup;
26+
- (instancetype)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app;
27+
- (instancetype)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app sharegroup:(EAGLSharegroup *)sharegroup;
2828

2929
- (UIInterfaceOrientation)currentInterfaceOrientation;
3030
- (void)setCurrentInterfaceOrientation:(UIInterfaceOrientation) orient;

addons/ofxiOS/src/core/ofxiOSGLKViewController.mm

+3-5
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ @implementation ofxiOSGLKViewController
2727

2828
@synthesize glView;
2929

30-
- (id)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app {
30+
- (instancetype)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app {
3131
return [self initWithFrame:frame app:app sharegroup:nil];
3232
}
3333

34-
- (id)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app sharegroup:(EAGLSharegroup *)sharegroup{
34+
- (instancetype)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app sharegroup:(EAGLSharegroup *)sharegroup{
3535
currentInterfaceOrientation = pendingInterfaceOrientation = UIInterfaceOrientationPortrait;
3636
if((self = [super init])) {
3737
currentInterfaceOrientation = pendingInterfaceOrientation = self.interfaceOrientation;
@@ -43,7 +43,7 @@ - (id)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app sharegroup:(EAGLSharegrou
4343
bFirstUpdate = NO;
4444
bAnimated = NO;
4545

46-
self.glView = [[[ofxiOSGLKView alloc] initWithFrame:frame andApp:app sharegroup:sharegroup] autorelease];
46+
self.glView = [[ofxiOSGLKView alloc] initWithFrame:frame andApp:app sharegroup:sharegroup];
4747
self.glView.delegate = self;
4848
}
4949

@@ -54,8 +54,6 @@ - (void) dealloc {
5454
[self.glView removeFromSuperview];
5555
self.glView.delegate = nil;
5656
self.glView = nil;
57-
58-
[super dealloc];
5957
}
6058

6159
- (void)viewDidLoad {

0 commit comments

Comments
 (0)