ladeiko / TopViewControllerDetection

TopViewControllerDetection - helper code (iOS) to detect current top visible UIViewController

Repository from Github https://github.comladeiko/TopViewControllerDetectionRepository from Github https://github.comladeiko/TopViewControllerDetection

TopViewControllerDetection

Build Status

Contains helper code (extension to UIApplication/UIViewController) to detect top visible view controller.

Installation

Cocoapods

This is the recommended way of installing this package.

  • Add the following line to your Podfile
pod 'TopViewControllerDetection'
  • Run the following command to fetch and build your dependencies
pod install

Manually

If you prefer to install this package manually, just follow these steps:

  • Make sure your project is a git repository. If it isn't, just run this command from your project root folder:
git init
  • Add TopViewControllerDetection as a git submodule by running the following command.
git submodules add https://github.com/ladeiko/TopViewControllerDetection.git
  • Add files ('.swift') from 'submodules/TopViewControllerDetection/Source' folder to your project.

Usage

Swift

See SwiftExample.swift

import TopViewControllerDetection

let absoluteTopViewController = UIApplication.shared.findTopViewController()

func viewDidLoad() {
	super.viewDidLoad()
	let topViewControllerRelativeToSelf = self.findTopViewController()
}


// Async version

self.findTopViewController { viewController in
    if let viewController =  viewController {
        // TODO
    }
}

Objective-C

See ObjCExample.m

@import TopViewControllerDetection;

UIViewController* const absoluteTopViewController = [[UIApplication sharedApplication] findTopViewController];

- (void)viewDidLoad {
	[super  viewDidLoad];
	UIViewController* const topViewControllerRelativeToSelf = [self findTopViewController];
}

Changelog

See CHANGELOG

LICENSE

This project is licensed under the MIT License - see the LICENSE file for details

About

TopViewControllerDetection - helper code (iOS) to detect current top visible UIViewController

License:MIT License


Languages

Language:Swift 70.1%Language:Objective-C 22.0%Language:Ruby 6.7%Language:C 1.2%