This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// Check whether active window is in fullscreen mode. | |
| /// - Parameter processIdentifier: the pid given by "NSWorkspace.shared.frontmostApplication?.processIdentifier" | |
| /// - Returns: true if fullscreen, false if windowed | |
| func isFullScreen(processIdentifier: pid_t) -> Bool { | |
| if let winArray: CFArray = CGWindowListCopyWindowInfo(.excludeDesktopElements, kCGNullWindowID) { | |
| for i in 0..<CFArrayGetCount(winArray) { | |
| if let window: [String : Any] = unsafeBitCast(CFArrayGetValueAtIndex(winArray, i), to: CFDictionary.self) as? [String : Any] { | |
| if let pid = window["kCGWindowOwnerPID"] as? Int32 { | |
| if pid == processIdentifier { | |
| if let bounds: [String : Any] = window["kCGWindowBounds"] as? [String : Any], let boundsWidth = bounds["Width"] as? CGFloat, let boundsHeight = bounds["Height"] as? CGFloat { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension AnyView { | |
| /// Return UIHostingController for a SwiftUI View. | |
| /// - Usage: let vc = AnyView( YourSwiftUIViewHere() ).asUIHostingController() | |
| /// - Created by Michel Storms. | |
| /// - Returns: UIHostingController ready to use with UIKit. | |
| func asUIHostingController() -> UIHostingController<AnyView> { | |
| return UIHostingController(rootView: self) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension UIViewController { | |
| var previousViewController: UIViewController? { | |
| guard let navigationController = navigationController else { return nil } | |
| let count = navigationController.viewControllers.count | |
| return count < 2 ? nil : navigationController.viewControllers[count - 2] | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension NSManagedObject { | |
| /// Print content of object to console. | |
| func printContent() { | |
| print("\nNSManagedObjectID: \(self.objectID) - key/value dump:") | |
| for key in self.entity.attributesByName.keys { | |
| print("\(key): \(self.value(forKey: key) ?? "nil")") | |
| } | |
| print("\n") | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| def createFolder(directory): | |
| try: | |
| if not os.path.exists(directory): | |
| os.makedirs(directory) | |
| except OSError: | |
| print ('Error: Creating directory. ' + directory) | |
NewerOlder