Skip to content

Commit dc25d22

Browse files
committed
Split the iOS and OS X AppDelegate classes
The only thing they share is their name.
1 parent e9bed69 commit dc25d22

6 files changed

Lines changed: 159 additions & 117 deletions

File tree

Example/AFNetworking Example.xcodeproj/project.pbxproj

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
291BFDD51BB9E85500FFB029 /* watchOS Example.app in Embed Watch Content */ = {isa = PBXBuildFile; fileRef = 291BFDB91BB9E85400FFB029 /* watchOS Example.app */; };
1212
291BFDEE1BB9E8C700FFB029 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 291BFDED1BB9E8C700FFB029 /* main.m */; };
1313
291BFDF31BB9E8C700FFB029 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 291BFDF21BB9E8C700FFB029 /* Assets.xcassets */; };
14-
291BFDFB1BB9E8DC00FFB029 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 29E6F1A91BB9DD9400A4466C /* AppDelegate.m */; };
1514
291BFDFD1BB9E8E500FFB029 /* Post.m in Sources */ = {isa = PBXBuildFile; fileRef = 29E6F19A1BB9DD7300A4466C /* Post.m */; };
1615
291BFDFE1BB9E8E900FFB029 /* User.m in Sources */ = {isa = PBXBuildFile; fileRef = 29E6F19C1BB9DD7300A4466C /* User.m */; };
1716
291BFDFF1BB9E8EC00FFB029 /* AFAppDotNetAPIClient.m in Sources */ = {isa = PBXBuildFile; fileRef = 29E6F19F1BB9DD7300A4466C /* AFAppDotNetAPIClient.m */; };
@@ -34,7 +33,6 @@
3433
29E6F1A41BB9DD7300A4466C /* Post.m in Sources */ = {isa = PBXBuildFile; fileRef = 29E6F19A1BB9DD7300A4466C /* Post.m */; };
3534
29E6F1A51BB9DD7300A4466C /* User.m in Sources */ = {isa = PBXBuildFile; fileRef = 29E6F19C1BB9DD7300A4466C /* User.m */; };
3635
29E6F1A61BB9DD7300A4466C /* AFAppDotNetAPIClient.m in Sources */ = {isa = PBXBuildFile; fileRef = 29E6F19F1BB9DD7300A4466C /* AFAppDotNetAPIClient.m */; };
37-
29E6F1AA1BB9DD9400A4466C /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 29E6F1A91BB9DD9400A4466C /* AppDelegate.m */; };
3836
29E6F1AC1BB9DDB600A4466C /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 29E6F1AB1BB9DDB600A4466C /* Assets.xcassets */; };
3937
29E6F1E11BB9E03600A4466C /* Launchscreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 29E6F1E01BB9E03600A4466C /* Launchscreen.storyboard */; };
4038
29E6F1E91BB9E37200A4466C /* NotificationCenter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 29E6F1E81BB9E37200A4466C /* NotificationCenter.framework */; };
@@ -43,6 +41,8 @@
4341
29E6F1F41BB9E37200A4466C /* Today Extension Example.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 29E6F1E61BB9E37200A4466C /* Today Extension Example.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
4442
29E6F1F91BB9E56200A4466C /* Post.m in Sources */ = {isa = PBXBuildFile; fileRef = 29E6F19A1BB9DD7300A4466C /* Post.m */; };
4543
29E6F1FA1BB9E56500A4466C /* User.m in Sources */ = {isa = PBXBuildFile; fileRef = 29E6F19C1BB9DD7300A4466C /* User.m */; };
44+
C2BFE0251C11870800BB258D /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = C2BFE0241C11870800BB258D /* AppDelegate.m */; };
45+
C2BFE0281C11872D00BB258D /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = C2BFE0271C11872D00BB258D /* AppDelegate.m */; };
4646
/* End PBXBuildFile section */
4747

4848
/* Begin PBXContainerItemProxy section */
@@ -135,8 +135,6 @@
135135
29E6F19C1BB9DD7300A4466C /* User.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = User.m; sourceTree = "<group>"; };
136136
29E6F19E1BB9DD7300A4466C /* AFAppDotNetAPIClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AFAppDotNetAPIClient.h; sourceTree = "<group>"; };
137137
29E6F19F1BB9DD7300A4466C /* AFAppDotNetAPIClient.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AFAppDotNetAPIClient.m; sourceTree = "<group>"; };
138-
29E6F1A81BB9DD9400A4466C /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
139-
29E6F1A91BB9DD9400A4466C /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
140138
29E6F1AB1BB9DDB600A4466C /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
141139
29E6F1E01BB9E03600A4466C /* Launchscreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = Launchscreen.storyboard; path = "iOS Example/Launchscreen.storyboard"; sourceTree = SOURCE_ROOT; };
142140
29E6F1E61BB9E37200A4466C /* Today Extension Example.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = "Today Extension Example.appex"; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -155,6 +153,10 @@
155153
29E6F2231BB9E76A00A4466C /* ExtensionDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ExtensionDelegate.m; sourceTree = "<group>"; };
156154
29E6F2251BB9E76A00A4466C /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
157155
29E6F2271BB9E76B00A4466C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
156+
C2BFE0231C11870800BB258D /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
157+
C2BFE0241C11870800BB258D /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
158+
C2BFE0261C11872D00BB258D /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
159+
C2BFE0271C11872D00BB258D /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
158160
/* End PBXFileReference section */
159161

160162
/* Begin PBXFrameworksBuildPhase section */
@@ -206,6 +208,8 @@
206208
291BFDE81BB9E8C700FFB029 /* OS X Example */ = {
207209
isa = PBXGroup;
208210
children = (
211+
C2BFE0231C11870800BB258D /* AppDelegate.h */,
212+
C2BFE0241C11870800BB258D /* AppDelegate.m */,
209213
291BFE0F1BB9EC4900FFB029 /* MainMenu.xib */,
210214
291BFDF21BB9E8C700FFB029 /* Assets.xcassets */,
211215
291BFDF71BB9E8C700FFB029 /* Info.plist */,
@@ -289,6 +293,8 @@
289293
29E6F1771BB9DCB500A4466C /* iOS Example */ = {
290294
isa = PBXGroup;
291295
children = (
296+
C2BFE0261C11872D00BB258D /* AppDelegate.h */,
297+
C2BFE0271C11872D00BB258D /* AppDelegate.m */,
292298
291BFE071BB9EB3400FFB029 /* Controllers */,
293299
291BFE0A1BB9EB3400FFB029 /* Views */,
294300
29E6F1781BB9DCB500A4466C /* Supporting Files */,
@@ -309,8 +315,6 @@
309315
29E6F1941BB9DD7300A4466C /* Classes */ = {
310316
isa = PBXGroup;
311317
children = (
312-
29E6F1A81BB9DD9400A4466C /* AppDelegate.h */,
313-
29E6F1A91BB9DD9400A4466C /* AppDelegate.m */,
314318
29E6F1981BB9DD7300A4466C /* Models */,
315319
29E6F19D1BB9DD7300A4466C /* Networking Extensions */,
316320
);
@@ -606,7 +610,7 @@
606610
buildActionMask = 2147483647;
607611
files = (
608612
291BFDFF1BB9E8EC00FFB029 /* AFAppDotNetAPIClient.m in Sources */,
609-
291BFDFB1BB9E8DC00FFB029 /* AppDelegate.m in Sources */,
613+
C2BFE0251C11870800BB258D /* AppDelegate.m in Sources */,
610614
291BFDFE1BB9E8E900FFB029 /* User.m in Sources */,
611615
291BFDFD1BB9E8E500FFB029 /* Post.m in Sources */,
612616
291BFDEE1BB9E8C700FFB029 /* main.m in Sources */,
@@ -631,9 +635,9 @@
631635
291BFE0D1BB9EB3400FFB029 /* GlobalTimelineViewController.m in Sources */,
632636
291BFE0E1BB9EB3400FFB029 /* PostTableViewCell.m in Sources */,
633637
29E6F1A51BB9DD7300A4466C /* User.m in Sources */,
634-
29E6F1AA1BB9DD9400A4466C /* AppDelegate.m in Sources */,
635638
29E6F17A1BB9DCB500A4466C /* main.m in Sources */,
636639
29E6F1A61BB9DD7300A4466C /* AFAppDotNetAPIClient.m in Sources */,
640+
C2BFE0281C11872D00BB258D /* AppDelegate.m in Sources */,
637641
);
638642
runOnlyForDeploymentPostprocessing = 0;
639643
};

Example/Classes/AppDelegate.m

Lines changed: 0 additions & 90 deletions
This file was deleted.

Example/OS X Example/AppDelegate.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// AppDelegate.h
2+
//
3+
// Copyright (c) 2012 Mattt Thompson (http://mattt.me/)
4+
//
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
//
12+
// The above copyright notice and this permission notice shall be included in
13+
// all copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
// THE SOFTWARE.
22+
23+
#import <Cocoa/Cocoa.h>
24+
25+
@interface AppDelegate : NSObject <NSApplicationDelegate>
26+
27+
@property (strong) IBOutlet NSWindow *window;
28+
@property (strong) IBOutlet NSTableView *tableView;
29+
@property (strong) IBOutlet NSArrayController *postsArrayController;
30+
31+
@end

Example/OS X Example/AppDelegate.m

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// AppDelegate.m
2+
//
3+
// Copyright (c) 2012 Mattt Thompson (http://mattt.me/)
4+
//
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
//
12+
// The above copyright notice and this permission notice shall be included in
13+
// all copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
// THE SOFTWARE.
22+
23+
#import "AppDelegate.h"
24+
@import AFNetworking;
25+
26+
#import "Post.h"
27+
#import "User.h"
28+
29+
@implementation AppDelegate
30+
31+
- (void)applicationDidFinishLaunching:(NSNotification *)notification {
32+
NSURLCache *URLCache = [[NSURLCache alloc] initWithMemoryCapacity:4 * 1024 * 1024 diskCapacity:20 * 1024 * 1024 diskPath:nil];
33+
[NSURLCache setSharedURLCache:URLCache];
34+
35+
[self.window makeKeyAndOrderFront:self];
36+
37+
[Post globalTimelinePostsWithBlock:^(NSArray *posts, NSError *error) {
38+
if (error) {
39+
NSAlert *alert = [[NSAlert alloc] init];
40+
alert.messageText = NSLocalizedString(@"Error", nil);
41+
alert.informativeText = error.localizedDescription;
42+
[alert addButtonWithTitle:NSLocalizedString(@"OK", nil)];
43+
[alert runModal];
44+
}
45+
46+
self.postsArrayController.content = posts;
47+
}];
48+
49+
[[NSNotificationCenter defaultCenter] addObserverForName:kUserProfileImageDidLoadNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notification) {
50+
[self.tableView reloadData];
51+
}];
52+
}
53+
54+
- (BOOL)applicationShouldHandleReopen:(NSApplication *)application
55+
hasVisibleWindows:(BOOL)flag
56+
{
57+
[self.window makeKeyAndOrderFront:self];
58+
59+
return YES;
60+
}
61+
62+
@end
Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,11 @@
2020
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
// THE SOFTWARE.
2222

23-
#import <Availability.h>
23+
#import <UIKit/UIKit.h>
2424

25-
#if __IPHONE_OS_VERSION_MIN_REQUIRED
26-
#import <UIKit/UIKit.h>
25+
@interface AppDelegate : NSObject <UIApplicationDelegate>
2726

28-
@interface AppDelegate : NSObject <UIApplicationDelegate>
27+
@property (nonatomic, strong) UIWindow *window;
28+
@property (nonatomic, strong) UINavigationController *navigationController;
2929

30-
@property (nonatomic, strong) UIWindow *window;
31-
@property (nonatomic, strong) UINavigationController *navigationController;
32-
33-
@end
34-
#else
35-
#import <Cocoa/Cocoa.h>
36-
37-
@interface AppDelegate : NSObject <NSApplicationDelegate>
38-
39-
@property (strong) IBOutlet NSWindow *window;
40-
@property (strong) IBOutlet NSTableView *tableView;
41-
@property (strong) IBOutlet NSArrayController *postsArrayController;
42-
43-
@end
44-
#endif
30+
@end

Example/iOS Example/AppDelegate.m

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// AppDelegate.m
2+
//
3+
// Copyright (c) 2012 Mattt Thompson (http://mattt.me/)
4+
//
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
//
12+
// The above copyright notice and this permission notice shall be included in
13+
// all copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
// THE SOFTWARE.
22+
23+
#import "AppDelegate.h"
24+
@import AFNetworking;
25+
26+
#import "GlobalTimelineViewController.h"
27+
28+
@implementation AppDelegate
29+
30+
- (BOOL)application:(__unused UIApplication *)application didFinishLaunchingWithOptions:(__unused NSDictionary *)launchOptions
31+
{
32+
NSURLCache *URLCache = [[NSURLCache alloc] initWithMemoryCapacity:4 * 1024 * 1024 diskCapacity:20 * 1024 * 1024 diskPath:nil];
33+
[NSURLCache setSharedURLCache:URLCache];
34+
35+
[[AFNetworkActivityIndicatorManager sharedManager] setEnabled:YES];
36+
37+
UITableViewController *viewController = [[GlobalTimelineViewController alloc] initWithStyle:UITableViewStylePlain];
38+
self.navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
39+
self.navigationController.navigationBar.tintColor = [UIColor darkGrayColor];
40+
41+
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
42+
self.window.backgroundColor = [UIColor whiteColor];
43+
self.window.rootViewController = self.navigationController;
44+
[self.window makeKeyAndVisible];
45+
46+
return YES;
47+
}
48+
49+
@end

0 commit comments

Comments
 (0)