Commit dc110fd1 by Daniel Dahan

fetches a given view controller type based on the return type of the property value

parent a77657d6
...@@ -99,6 +99,7 @@ ...@@ -99,6 +99,7 @@
965E81211DD4D5C800D61E4B /* TextStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB79D1CB40DC500C806FE /* TextStorage.swift */; }; 965E81211DD4D5C800D61E4B /* TextStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB79D1CB40DC500C806FE /* TextStorage.swift */; };
965E81221DD4D5C800D61E4B /* TextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB79E1CB40DC500C806FE /* TextView.swift */; }; 965E81221DD4D5C800D61E4B /* TextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB79E1CB40DC500C806FE /* TextView.swift */; };
965E81261DD4D7C800D61E4B /* CharacterAttribute.swift in Sources */ = {isa = PBXBuildFile; fileRef = 961276621DCD8B1800A7D920 /* CharacterAttribute.swift */; }; 965E81261DD4D7C800D61E4B /* CharacterAttribute.swift in Sources */ = {isa = PBXBuildFile; fileRef = 961276621DCD8B1800A7D920 /* CharacterAttribute.swift */; };
9667A2491F33D5E200C45078 /* Material+UIViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9667A2481F33D5E200C45078 /* Material+UIViewController.swift */; };
966C17731F0439F600D3E83C /* Material+MotionAnimation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 966C17721F0439F600D3E83C /* Material+MotionAnimation.swift */; }; 966C17731F0439F600D3E83C /* Material+MotionAnimation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 966C17721F0439F600D3E83C /* Material+MotionAnimation.swift */; };
9685D5AF1F0F04CB00AFEB79 /* CardCollectionViewCell.swift in Headers */ = {isa = PBXBuildFile; fileRef = 9656895E1F002F16001C656D /* CardCollectionViewCell.swift */; settings = {ATTRIBUTES = (Public, ); }; }; 9685D5AF1F0F04CB00AFEB79 /* CardCollectionViewCell.swift in Headers */ = {isa = PBXBuildFile; fileRef = 9656895E1F002F16001C656D /* CardCollectionViewCell.swift */; settings = {ATTRIBUTES = (Public, ); }; };
9685D5B01F0F04CB00AFEB79 /* CardCollectionViewController.swift in Headers */ = {isa = PBXBuildFile; fileRef = 965689601F002F4C001C656D /* CardCollectionViewController.swift */; settings = {ATTRIBUTES = (Public, ); }; }; 9685D5B01F0F04CB00AFEB79 /* CardCollectionViewController.swift in Headers */ = {isa = PBXBuildFile; fileRef = 965689601F002F4C001C656D /* CardCollectionViewController.swift */; settings = {ATTRIBUTES = (Public, ); }; };
...@@ -229,6 +230,7 @@ ...@@ -229,6 +230,7 @@
9656895E1F002F16001C656D /* CardCollectionViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CardCollectionViewCell.swift; sourceTree = "<group>"; }; 9656895E1F002F16001C656D /* CardCollectionViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CardCollectionViewCell.swift; sourceTree = "<group>"; };
965689601F002F4C001C656D /* CardCollectionViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CardCollectionViewController.swift; sourceTree = "<group>"; }; 965689601F002F4C001C656D /* CardCollectionViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CardCollectionViewController.swift; sourceTree = "<group>"; };
9658F2161CD6FA4700B902C1 /* IconButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IconButton.swift; sourceTree = "<group>"; }; 9658F2161CD6FA4700B902C1 /* IconButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IconButton.swift; sourceTree = "<group>"; };
9667A2481F33D5E200C45078 /* Material+UIViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Material+UIViewController.swift"; sourceTree = "<group>"; };
966C17721F0439F600D3E83C /* Material+MotionAnimation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Material+MotionAnimation.swift"; sourceTree = "<group>"; }; 966C17721F0439F600D3E83C /* Material+MotionAnimation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Material+MotionAnimation.swift"; sourceTree = "<group>"; };
966ECF291CF4C20100BB0BDF /* CollectionReusableView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CollectionReusableView.swift; sourceTree = "<group>"; }; 966ECF291CF4C20100BB0BDF /* CollectionReusableView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CollectionReusableView.swift; sourceTree = "<group>"; };
967A48181D0F425A00B8CEB7 /* StatusBarController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatusBarController.swift; sourceTree = "<group>"; }; 967A48181D0F425A00B8CEB7 /* StatusBarController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatusBarController.swift; sourceTree = "<group>"; };
...@@ -784,6 +786,7 @@ ...@@ -784,6 +786,7 @@
96C1C8801D42C62800E6608F /* Material+Array.swift */, 96C1C8801D42C62800E6608F /* Material+Array.swift */,
962864591D53FE3E00690B69 /* Material+UIWindow.swift */, 962864591D53FE3E00690B69 /* Material+UIWindow.swift */,
966C17721F0439F600D3E83C /* Material+MotionAnimation.swift */, 966C17721F0439F600D3E83C /* Material+MotionAnimation.swift */,
9667A2481F33D5E200C45078 /* Material+UIViewController.swift */,
); );
name = Extension; name = Extension;
sourceTree = "<group>"; sourceTree = "<group>";
...@@ -1009,6 +1012,7 @@ ...@@ -1009,6 +1012,7 @@
965E81031DD4D5C800D61E4B /* CollectionView.swift in Sources */, 965E81031DD4D5C800D61E4B /* CollectionView.swift in Sources */,
965E81041DD4D5C800D61E4B /* CollectionViewCell.swift in Sources */, 965E81041DD4D5C800D61E4B /* CollectionViewCell.swift in Sources */,
96A180941F2E2B6E006BD69D /* MotionCAAnimation.swift in Sources */, 96A180941F2E2B6E006BD69D /* MotionCAAnimation.swift in Sources */,
9667A2491F33D5E200C45078 /* Material+UIViewController.swift in Sources */,
965E81071DD4D5C800D61E4B /* CollectionViewLayout.swift in Sources */, 965E81071DD4D5C800D61E4B /* CollectionViewLayout.swift in Sources */,
96A180A41F2E2B6E006BD69D /* TransitionPreprocessor.swift in Sources */, 96A180A41F2E2B6E006BD69D /* TransitionPreprocessor.swift in Sources */,
965E81081DD4D5C800D61E4B /* CollectionReusableView.swift in Sources */, 965E81081DD4D5C800D61E4B /* CollectionReusableView.swift in Sources */,
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
<string>FMWK</string> <string>FMWK</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>2.8.1</string> <string>2.9.0</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
......
...@@ -43,14 +43,7 @@ extension UIViewController { ...@@ -43,14 +43,7 @@ extension UIViewController {
through child UIViewControllers. through child UIViewControllers.
*/ */
public var fabMenuController: FABMenuController? { public var fabMenuController: FABMenuController? {
var viewController: UIViewController? = self return findViewControllerType()
while nil != viewController {
if viewController is FABMenuController {
return viewController as? FABMenuController
}
viewController = viewController?.parent
}
return nil
} }
} }
......
/*
* Copyright (C) 2015 - 2017, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.com>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of CosmicMind nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import UIKit
internal extension UIViewController {
/**
Finds a view controller with a given type based on
the view controller subclass.
- Returns: An optional of type T.
*/
func findViewControllerType<T: UIViewController>() -> T? {
var v: UIViewController? = self
while nil != v {
if v is T {
return v as? T
}
v = v?.parent
}
return nil
}
}
...@@ -38,19 +38,12 @@ public enum NavigationDrawerPosition: Int { ...@@ -38,19 +38,12 @@ public enum NavigationDrawerPosition: Int {
extension UIViewController { extension UIViewController {
/** /**
A convenience property that provides access to the NavigationDrawerController. A convenience property that provides access to the NavigationDrawerController.
This is the recommended method of accessing the NavigationDrawerController This is the recommended method of accessing the NavigationDrawerController
through child UIViewControllers. through child UIViewControllers.
*/ */
public var navigationDrawerController: NavigationDrawerController? { public var navigationDrawerController: NavigationDrawerController? {
var viewController: UIViewController? = self return findViewControllerType()
while nil != viewController {
if viewController is NavigationDrawerController {
return viewController as? NavigationDrawerController
}
viewController = viewController?.parent
}
return nil
} }
} }
......
...@@ -30,22 +30,15 @@ ...@@ -30,22 +30,15 @@
import UIKit import UIKit
extension UIViewController { public extension UIViewController {
/** /**
A convenience property that provides access to the SearchBarController. A convenience property that provides access to the SearchBarController.
This is the recommended method of accessing the SearchBarController This is the recommended method of accessing the SearchBarController
through child UIViewControllers. through child UIViewControllers.
*/ */
public var searchBarController: SearchBarController? { var searchBarController: SearchBarController? {
var viewController: UIViewController? = self return findViewControllerType()
while nil != viewController { }
if viewController is SearchBarController {
return viewController as? SearchBarController
}
viewController = viewController?.parent
}
return nil
}
} }
open class SearchBarController: StatusBarController { open class SearchBarController: StatusBarController {
......
...@@ -78,14 +78,7 @@ extension UIViewController { ...@@ -78,14 +78,7 @@ extension UIViewController {
through child UIViewControllers. through child UIViewControllers.
*/ */
public var snackbarController: SnackbarController? { public var snackbarController: SnackbarController? {
var viewController: UIViewController? = self return findViewControllerType()
while nil != viewController {
if viewController is SnackbarController {
return viewController as? SnackbarController
}
viewController = viewController?.parent
}
return nil
} }
} }
......
...@@ -37,14 +37,7 @@ extension UIViewController { ...@@ -37,14 +37,7 @@ extension UIViewController {
through child UIViewControllers. through child UIViewControllers.
*/ */
public var statusBarController: StatusBarController? { public var statusBarController: StatusBarController? {
var viewController: UIViewController? = self return findViewControllerType()
while nil != viewController {
if viewController is StatusBarController {
return viewController as? StatusBarController
}
viewController = viewController?.parent
}
return nil
} }
} }
......
...@@ -60,14 +60,7 @@ extension UIViewController { ...@@ -60,14 +60,7 @@ extension UIViewController {
through child UIViewControllers. through child UIViewControllers.
*/ */
public var tabsController: TabsController? { public var tabsController: TabsController? {
var viewController: UIViewController? = self return findViewControllerType()
while nil != viewController {
if viewController is TabsController {
return viewController as? TabsController
}
viewController = viewController?.parent
}
return nil
} }
} }
......
...@@ -30,22 +30,15 @@ ...@@ -30,22 +30,15 @@
import UIKit import UIKit
extension UIViewController { public extension UIViewController {
/** /**
A convenience property that provides access to the ToolbarController. A convenience property that provides access to the ToolbarController.
This is the recommended method of accessing the ToolbarController This is the recommended method of accessing the ToolbarController
through child UIViewControllers. through child UIViewControllers.
*/ */
public var toolbarController: ToolbarController? { var toolbarController: ToolbarController? {
var viewController: UIViewController? = self return findViewControllerType()
while nil != viewController { }
if viewController is ToolbarController {
return viewController as? ToolbarController
}
viewController = viewController?.parent
}
return nil
}
} }
@objc(ToolbarController) @objc(ToolbarController)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment