From 549e447a28ae977169dfab6fcb7bfa35db96c894 Mon Sep 17 00:00:00 2001 From: Sami Samhuri Date: Tue, 28 Apr 2015 08:14:30 -0400 Subject: [PATCH] make safeCast global --- Blog.xcodeproj/project.pbxproj | 6 ++++++ Blog/AppDelegate.m | 7 ++----- Blog/Functions.h | 11 +++++++++++ Blog/Functions.m | 13 +++++++++++++ 4 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 Blog/Functions.h create mode 100644 Blog/Functions.m diff --git a/Blog.xcodeproj/project.pbxproj b/Blog.xcodeproj/project.pbxproj index 2691cfd..b84a461 100644 --- a/Blog.xcodeproj/project.pbxproj +++ b/Blog.xcodeproj/project.pbxproj @@ -23,6 +23,7 @@ 1BCFCF6DB93786CC2EDB8F69 /* PostCollection.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BCFC3B62AA92DB07923F7C1 /* PostCollection.m */; }; 1BCFCFF473F6CE1B00AD9556 /* MuseoSans-700-Italic.otf in Resources */ = {isa = PBXBuildFile; fileRef = 1BCFCE2128EAD786A819C61A /* MuseoSans-700-Italic.otf */; }; 30089596C2F733D451A454E8 /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1613DC56A86AFA7E50460A37 /* libPods.a */; }; + 7B2B43511AED5BA500BAC4E2 /* Functions.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B2B43501AED5BA500BAC4E2 /* Functions.m */; }; 7B4070531AE46BC9000C2E43 /* auth.json in Resources */ = {isa = PBXBuildFile; fileRef = 7B4070521AE46BC9000C2E43 /* auth.json */; }; 7B5C4BDF19F2606900667D48 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B5C4BDE19F2606900667D48 /* main.m */; }; 7B5C4BE219F2606900667D48 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B5C4BE119F2606900667D48 /* AppDelegate.m */; }; @@ -77,6 +78,8 @@ 216E09E2B9970083489FA869 /* Pods-Blog.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Blog.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Blog/Pods-Blog.debug.xcconfig"; sourceTree = ""; }; 52D4D1E7D7915ADAD8A3C902 /* Pods-Blog.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Blog.release.xcconfig"; path = "Pods/Target Support Files/Pods-Blog/Pods-Blog.release.xcconfig"; sourceTree = ""; }; 7160E151335CBA3861FBD44D /* libPods-Blog.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Blog.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + 7B2B434F1AED5BA500BAC4E2 /* Functions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Functions.h; sourceTree = ""; }; + 7B2B43501AED5BA500BAC4E2 /* Functions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Functions.m; sourceTree = ""; }; 7B4070521AE46BC9000C2E43 /* auth.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = auth.json; sourceTree = ""; }; 7B5C4BD919F2606900667D48 /* Blog.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Blog.app; sourceTree = BUILT_PRODUCTS_DIR; }; 7B5C4BDD19F2606900667D48 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -214,6 +217,8 @@ 1BCFCE26B630D546311BB715 /* ChangeTitleViewController.m */, 1BCFCDD73D4AE8F16A9C9E3D /* ChangeTitleViewController.h */, 1BCFC29A0845EAB04BFDAD67 /* Fonts */, + 7B2B434F1AED5BA500BAC4E2 /* Functions.h */, + 7B2B43501AED5BA500BAC4E2 /* Functions.m */, ); path = Blog; sourceTree = ""; @@ -482,6 +487,7 @@ 7B9E64421A22F3840072FF42 /* BlogService.m in Sources */, 7B5C4BDF19F2606900667D48 /* main.m in Sources */, 7BF029331A27117200E42EDE /* ModelStore.m in Sources */, + 7B2B43511AED5BA500BAC4E2 /* Functions.m in Sources */, 7BF029381A280CB200E42EDE /* BlogController.m in Sources */, 7B5C4BE819F2606900667D48 /* EditorViewController.m in Sources */, 7BE3A0351AE461E700E45CCB /* PreviewViewController.m in Sources */, diff --git a/Blog/AppDelegate.m b/Blog/AppDelegate.m index c4a9671..56a27bb 100644 --- a/Blog/AppDelegate.m +++ b/Blog/AppDelegate.m @@ -14,6 +14,7 @@ #import "ModelStore.h" #import "JSONHTTPClient.h" #import "BlogController.h" +#import "Functions.h" @interface AppDelegate () @@ -77,7 +78,7 @@ } NSLog(@"[WARNING] No auth.json found. Blog will be read-only."); return nil; -}; +} - (void)applicationWillResignActive:(UIApplication *)application { // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. @@ -103,10 +104,6 @@ #pragma mark - UISplitViewDelegate methods -id safeCast(id obj, __unsafe_unretained Class class) { - return [obj isKindOfClass:class] ? obj : nil; -} - - (BOOL) splitViewController:(UISplitViewController *)splitViewController collapseSecondaryViewController:(UIViewController *)secondaryViewController ontoPrimaryViewController:(UIViewController *)primaryViewController { UINavigationController *navigationController = [secondaryViewController isKindOfClass:[UINavigationController class]] ? (UINavigationController *)secondaryViewController diff --git a/Blog/Functions.h b/Blog/Functions.h new file mode 100644 index 0000000..361b627 --- /dev/null +++ b/Blog/Functions.h @@ -0,0 +1,11 @@ +// +// Functions.h +// Blog +// +// Created by Sami Samhuri on 2015-04-26. +// Copyright (c) 2015 Guru Logic Inc. All rights reserved. +// + +@import Foundation; + +extern id safeCast(id obj, __unsafe_unretained Class class); diff --git a/Blog/Functions.m b/Blog/Functions.m new file mode 100644 index 0000000..7bf08b2 --- /dev/null +++ b/Blog/Functions.m @@ -0,0 +1,13 @@ +// +// Functions.m +// Blog +// +// Created by Sami Samhuri on 2015-04-26. +// Copyright (c) 2015 Guru Logic Inc. All rights reserved. +// + +#import "Functions.h" + +id safeCast(id obj, __unsafe_unretained Class class) { + return [obj isKindOfClass:class] ? obj : nil; +}