Skip to content

Instantly share code, notes, and snippets.

@KalpeshTalkar
Last active June 10, 2017 10:40
Show Gist options
  • Save KalpeshTalkar/e7769e8875e408806d41cf2eae2ebdf8 to your computer and use it in GitHub Desktop.
Save KalpeshTalkar/e7769e8875e408806d41cf2eae2ebdf8 to your computer and use it in GitHub Desktop.
The class enables the UIDebuggingInformationOverlay (which is a private UIWindow subclass). This helps developers and designers debug the app.
//
// Copyright © 2017 Kalpesh Talkar. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// For support: https://gist.github.com/KalpeshTalkar/e7769e8875e408806d41cf2eae2ebdf8
//
import UIKit
/// The class enables the UIDebuggingInformationOverlay (which is a private UIWindow subclass)
/// This helps developers and designers debug the app.
class KDebugInfoOverlay {
/// UIDebuggingInformationOverlay private class
private static var overlayClass: UIWindow.Type?
/// Configure and show UIDebuggingInformationOverlay
public static func configureAndShowDebugInfoOverlay() {
configureDebugInfoOverlay()
showDebugInfoOverlay()
}
/// Configure UIDebuggingInformationOverlay
public static func configureDebugInfoOverlay() {
overlayClass = NSClassFromString("UIDebuggingInformationOverlay") as? UIWindow.Type
_ = overlayClass?.perform(NSSelectorFromString("prepareDebuggingOverlay"))
}
/// Show UIDebuggingInformationOverlay
public static func showDebugInfoOverlay() {
// Configure the UIDebuggingInformationOverlay if the class is nil
if (nil == overlayClass) {
configureDebugInfoOverlay()
}
// Show UIDebuggingInformationOverlay
let overlay = overlayClass?.perform(NSSelectorFromString("overlay")).takeUnretainedValue() as? UIWindow
_ = overlay?.perform(NSSelectorFromString("toggleVisibility"))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment