diff --git a/Example/AppDelegate.swift b/Example/AppDelegate.swift new file mode 100644 index 0000000..fe0017e --- /dev/null +++ b/Example/AppDelegate.swift @@ -0,0 +1,48 @@ +// +// AppDelegate.swift +// Example +// +// Created by Rui Peres on 15/02/2016. +// Copyright © 2016 Velhotes. All rights reserved. +// + +import UIKit +import Lighter + + +@UIApplicationMain +class AppDelegate: UIResponder, UIApplicationDelegate { + + var window: UIWindow? + + func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { + + UIViewController.startLogging() + return true + } + + func applicationWillResignActive(application: UIApplication) { + // 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. + // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. + } + + func applicationDidEnterBackground(application: UIApplication) { + // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. + // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. + } + + func applicationWillEnterForeground(application: UIApplication) { + // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. + } + + func applicationDidBecomeActive(application: UIApplication) { + // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. + } + + func applicationWillTerminate(application: UIApplication) { + // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. + } + + +} + diff --git a/Example/Assets.xcassets/AppIcon.appiconset/Contents.json b/Example/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..eeea76c --- /dev/null +++ b/Example/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,73 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "3x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "83.5x83.5", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Example/Base.lproj/LaunchScreen.storyboard b/Example/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 0000000..2e721e1 --- /dev/null +++ b/Example/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Example/Base.lproj/Main.storyboard b/Example/Base.lproj/Main.storyboard new file mode 100644 index 0000000..e5b19ce --- /dev/null +++ b/Example/Base.lproj/Main.storyboard @@ -0,0 +1,136 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Example/Info.plist b/Example/Info.plist new file mode 100644 index 0000000..40c6215 --- /dev/null +++ b/Example/Info.plist @@ -0,0 +1,47 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/Example/ViewController.swift b/Example/ViewController.swift new file mode 100644 index 0000000..39f9449 --- /dev/null +++ b/Example/ViewController.swift @@ -0,0 +1,12 @@ +// +// ViewController.swift +// Example +// +// Created by Rui Peres on 15/02/2016. +// Copyright © 2016 Velhotes. All rights reserved. +// + +import UIKit + +class ViewController: UIViewController { } + diff --git a/Lighter.xcodeproj/project.pbxproj b/Lighter.xcodeproj/project.pbxproj index 5497ef0..2f6edec 100644 --- a/Lighter.xcodeproj/project.pbxproj +++ b/Lighter.xcodeproj/project.pbxproj @@ -7,6 +7,17 @@ objects = { /* Begin PBXBuildFile section */ + C70B74D51C72313C004C66C7 /* ViewControllerExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C70B74D41C72313C004C66C7 /* ViewControllerExtension.swift */; }; + C70B74D71C7234CD004C66C7 /* NSObjectExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C70B74D61C7234CD004C66C7 /* NSObjectExtension.swift */; }; + C70B74D91C723B23004C66C7 /* Logger.swift in Sources */ = {isa = PBXBuildFile; fileRef = C70B74D81C723B23004C66C7 /* Logger.swift */; }; + C70B74E11C7240F7004C66C7 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C70B74E01C7240F7004C66C7 /* AppDelegate.swift */; }; + C70B74E31C7240F7004C66C7 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C70B74E21C7240F7004C66C7 /* ViewController.swift */; }; + C70B74E61C7240F7004C66C7 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C70B74E41C7240F7004C66C7 /* Main.storyboard */; }; + C70B74E81C7240F7004C66C7 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C70B74E71C7240F7004C66C7 /* Assets.xcassets */; }; + C70B74EB1C7240F7004C66C7 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C70B74E91C7240F7004C66C7 /* LaunchScreen.storyboard */; }; + C70B74F01C724147004C66C7 /* ViewControllerExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C70B74D41C72313C004C66C7 /* ViewControllerExtension.swift */; }; + C70B74F11C724147004C66C7 /* NSObjectExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C70B74D61C7234CD004C66C7 /* NSObjectExtension.swift */; }; + C70B74F21C724147004C66C7 /* Logger.swift in Sources */ = {isa = PBXBuildFile; fileRef = C70B74D81C723B23004C66C7 /* Logger.swift */; }; C7BCCCC81C6FBFB5003EE0C5 /* Lighter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C7BCCCBD1C6FBFB5003EE0C5 /* Lighter.framework */; }; C7BCCCCD1C6FBFB5003EE0C5 /* LighterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7BCCCCC1C6FBFB5003EE0C5 /* LighterTests.swift */; }; /* End PBXBuildFile section */ @@ -22,6 +33,16 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + C70B74D41C72313C004C66C7 /* ViewControllerExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewControllerExtension.swift; sourceTree = ""; }; + C70B74D61C7234CD004C66C7 /* NSObjectExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSObjectExtension.swift; sourceTree = ""; }; + C70B74D81C723B23004C66C7 /* Logger.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Logger.swift; sourceTree = ""; }; + C70B74DE1C7240F7004C66C7 /* Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Example.app; sourceTree = BUILT_PRODUCTS_DIR; }; + C70B74E01C7240F7004C66C7 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + C70B74E21C7240F7004C66C7 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; + C70B74E51C7240F7004C66C7 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + C70B74E71C7240F7004C66C7 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + C70B74EA1C7240F7004C66C7 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + C70B74EC1C7240F7004C66C7 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; C7BCCCBD1C6FBFB5003EE0C5 /* Lighter.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Lighter.framework; sourceTree = BUILT_PRODUCTS_DIR; }; C7BCCCC21C6FBFB5003EE0C5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; C7BCCCC71C6FBFB5003EE0C5 /* LighterTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = LighterTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -30,6 +51,13 @@ /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ + C70B74DB1C7240F7004C66C7 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; C7BCCCB91C6FBFB5003EE0C5 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; @@ -48,9 +76,23 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + C70B74DF1C7240F7004C66C7 /* Example */ = { + isa = PBXGroup; + children = ( + C70B74E01C7240F7004C66C7 /* AppDelegate.swift */, + C70B74E21C7240F7004C66C7 /* ViewController.swift */, + C70B74E41C7240F7004C66C7 /* Main.storyboard */, + C70B74E71C7240F7004C66C7 /* Assets.xcassets */, + C70B74E91C7240F7004C66C7 /* LaunchScreen.storyboard */, + C70B74EC1C7240F7004C66C7 /* Info.plist */, + ); + path = Example; + sourceTree = ""; + }; C7BCCCB31C6FBFB5003EE0C5 = { isa = PBXGroup; children = ( + C70B74DF1C7240F7004C66C7 /* Example */, C7BCCCBF1C6FBFB5003EE0C5 /* Lighter */, C7BCCCCB1C6FBFB5003EE0C5 /* LighterTests */, C7BCCCBE1C6FBFB5003EE0C5 /* Products */, @@ -62,6 +104,7 @@ children = ( C7BCCCBD1C6FBFB5003EE0C5 /* Lighter.framework */, C7BCCCC71C6FBFB5003EE0C5 /* LighterTests.xctest */, + C70B74DE1C7240F7004C66C7 /* Example.app */, ); name = Products; sourceTree = ""; @@ -70,6 +113,9 @@ isa = PBXGroup; children = ( C7BCCCC21C6FBFB5003EE0C5 /* Info.plist */, + C70B74D41C72313C004C66C7 /* ViewControllerExtension.swift */, + C70B74D61C7234CD004C66C7 /* NSObjectExtension.swift */, + C70B74D81C723B23004C66C7 /* Logger.swift */, ); path = Lighter; sourceTree = ""; @@ -96,6 +142,23 @@ /* End PBXHeadersBuildPhase section */ /* Begin PBXNativeTarget section */ + C70B74DD1C7240F7004C66C7 /* Example */ = { + isa = PBXNativeTarget; + buildConfigurationList = C70B74ED1C7240F7004C66C7 /* Build configuration list for PBXNativeTarget "Example" */; + buildPhases = ( + C70B74DA1C7240F7004C66C7 /* Sources */, + C70B74DB1C7240F7004C66C7 /* Frameworks */, + C70B74DC1C7240F7004C66C7 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = Example; + productName = Example; + productReference = C70B74DE1C7240F7004C66C7 /* Example.app */; + productType = "com.apple.product-type.application"; + }; C7BCCCBC1C6FBFB5003EE0C5 /* Lighter */ = { isa = PBXNativeTarget; buildConfigurationList = C7BCCCD11C6FBFB5003EE0C5 /* Build configuration list for PBXNativeTarget "Lighter" */; @@ -142,6 +205,9 @@ LastUpgradeCheck = 0720; ORGANIZATIONNAME = Velhotes; TargetAttributes = { + C70B74DD1C7240F7004C66C7 = { + CreatedOnToolsVersion = 7.2.1; + }; C7BCCCBC1C6FBFB5003EE0C5 = { CreatedOnToolsVersion = 7.2.1; }; @@ -156,6 +222,7 @@ hasScannedForEncodings = 0; knownRegions = ( en, + Base, ); mainGroup = C7BCCCB31C6FBFB5003EE0C5; productRefGroup = C7BCCCBE1C6FBFB5003EE0C5 /* Products */; @@ -164,11 +231,22 @@ targets = ( C7BCCCBC1C6FBFB5003EE0C5 /* Lighter */, C7BCCCC61C6FBFB5003EE0C5 /* LighterTests */, + C70B74DD1C7240F7004C66C7 /* Example */, ); }; /* End PBXProject section */ /* Begin PBXResourcesBuildPhase section */ + C70B74DC1C7240F7004C66C7 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + C70B74EB1C7240F7004C66C7 /* LaunchScreen.storyboard in Resources */, + C70B74E81C7240F7004C66C7 /* Assets.xcassets in Resources */, + C70B74E61C7240F7004C66C7 /* Main.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; C7BCCCBB1C6FBFB5003EE0C5 /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; @@ -186,10 +264,25 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ + C70B74DA1C7240F7004C66C7 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + C70B74F21C724147004C66C7 /* Logger.swift in Sources */, + C70B74E31C7240F7004C66C7 /* ViewController.swift in Sources */, + C70B74E11C7240F7004C66C7 /* AppDelegate.swift in Sources */, + C70B74F01C724147004C66C7 /* ViewControllerExtension.swift in Sources */, + C70B74F11C724147004C66C7 /* NSObjectExtension.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; C7BCCCB81C6FBFB5003EE0C5 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + C70B74D51C72313C004C66C7 /* ViewControllerExtension.swift in Sources */, + C70B74D91C723B23004C66C7 /* Logger.swift in Sources */, + C70B74D71C7234CD004C66C7 /* NSObjectExtension.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -211,7 +304,48 @@ }; /* End PBXTargetDependency section */ +/* Begin PBXVariantGroup section */ + C70B74E41C7240F7004C66C7 /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + C70B74E51C7240F7004C66C7 /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + C70B74E91C7240F7004C66C7 /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + C70B74EA1C7240F7004C66C7 /* Base */, + ); + name = LaunchScreen.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + /* Begin XCBuildConfiguration section */ + C70B74EE1C7240F7004C66C7 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + INFOPLIST_FILE = Example/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = velhotes.Example; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + C70B74EF1C7240F7004C66C7 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + INFOPLIST_FILE = Example/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = velhotes.Example; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; C7BCCCCF1C6FBFB5003EE0C5 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { @@ -304,6 +438,7 @@ C7BCCCD21C6FBFB5003EE0C5 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_MODULES = YES; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; @@ -314,12 +449,14 @@ PRODUCT_BUNDLE_IDENTIFIER = velhotes.Lighter; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; }; name = Debug; }; C7BCCCD31C6FBFB5003EE0C5 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_MODULES = YES; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; @@ -356,6 +493,14 @@ /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ + C70B74ED1C7240F7004C66C7 /* Build configuration list for PBXNativeTarget "Example" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + C70B74EE1C7240F7004C66C7 /* Debug */, + C70B74EF1C7240F7004C66C7 /* Release */, + ); + defaultConfigurationIsVisible = 0; + }; C7BCCCB71C6FBFB5003EE0C5 /* Build configuration list for PBXProject "Lighter" */ = { isa = XCConfigurationList; buildConfigurations = ( @@ -372,6 +517,7 @@ C7BCCCD31C6FBFB5003EE0C5 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; C7BCCCD41C6FBFB5003EE0C5 /* Build configuration list for PBXNativeTarget "LighterTests" */ = { isa = XCConfigurationList; @@ -380,6 +526,7 @@ C7BCCCD61C6FBFB5003EE0C5 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; diff --git a/Lighter.xcodeproj/xcshareddata/xcschemes/Lighter.xcscheme b/Lighter.xcodeproj/xcshareddata/xcschemes/Lighter.xcscheme new file mode 100644 index 0000000..dbfd120 --- /dev/null +++ b/Lighter.xcodeproj/xcshareddata/xcschemes/Lighter.xcscheme @@ -0,0 +1,99 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Lighter/Logger.swift b/Lighter/Logger.swift new file mode 100644 index 0000000..aa9f276 --- /dev/null +++ b/Lighter/Logger.swift @@ -0,0 +1,52 @@ +// +// Logger.swift +// Lighter +// +// Created by Rui Peres on 15/02/2016. +// Copyright © 2016 Velhotes. All rights reserved. +// + +import UIKit + +struct Logger { + + private static func log(level: Int, viewController: UIViewController) { + + var paddingItems = ""; + + for _ in 0.. %@", arguments: [paddingItems, viewController.description]) + print(infoLevel) + } + + static func printPath(viewController: UIViewController) { + + let parentViewController = viewController.parentViewController + + switch parentViewController { + + case _ where parentViewController?.isMemberOfClass(UINavigationController.self) != nil: + + guard + let navigationController = parentViewController as? UINavigationController, + let index = navigationController.viewControllers.indexOf(viewController) + else { + return + } + + log(index, viewController: viewController) + + case _ where parentViewController?.isMemberOfClass(UITabBarController.self) != nil: + + log(1, viewController: viewController) + + case _ where parentViewController != nil: fallthrough + default: + log(0, viewController: viewController) + } + } +} diff --git a/Lighter/NSObjectExtension.swift b/Lighter/NSObjectExtension.swift new file mode 100644 index 0000000..39ecd8f --- /dev/null +++ b/Lighter/NSObjectExtension.swift @@ -0,0 +1,28 @@ +// +// NSObjectExtension.swift +// Lighter +// +// Created by Rui Peres on 15/02/2016. +// Copyright © 2016 Velhotes. All rights reserved. +// + +import Foundation +import CoreFoundation + +extension NSObject { + + class func swizzleMethodSelector(lhs: Selector, rhs: Selector, c: AnyClass) { + + let originalMethod = class_getInstanceMethod(self, lhs) + let swizzledMethod = class_getInstanceMethod(self, rhs) + + let didAddMethod = class_addMethod(self, lhs, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod)) + + if didAddMethod { + class_replaceMethod(self, rhs, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod)) + } + else { + method_exchangeImplementations(originalMethod, swizzledMethod); + } + } +} diff --git a/Lighter/ViewControllerExtension.swift b/Lighter/ViewControllerExtension.swift new file mode 100644 index 0000000..fbc1951 --- /dev/null +++ b/Lighter/ViewControllerExtension.swift @@ -0,0 +1,42 @@ +// +// ViewControllerExtension.swift +// Lighter +// +// Created by Rui Peres on 15/02/2016. +// Copyright © 2016 Velhotes. All rights reserved. +// + +import UIKit + +public extension UIViewController { + + private static var isSwizzled: Bool = false + private static let lock = dispatch_queue_create("swizzling.lock", DISPATCH_QUEUE_SERIAL) + + public static func startLogging() { + + dispatch_sync(lock) { + + guard isSwizzled == false else { return } + swizzleMethodSelector("viewWillAppear:", rhs: "swizzviewDidAppear:", c: UIViewController.self) + isSwizzled = true + } + } + + public static func stopLogging() { + + dispatch_sync(lock) { + + guard isSwizzled == true else { return } + swizzleMethodSelector("swizzviewDidAppear:", rhs: "viewWillAppear:", c: UIViewController.self) + isSwizzled = false + } + } + + func swizzviewDidAppear(animated: Bool) { + + Logger.printPath(self) + swizzviewDidAppear(animated) + } +} +