Skip to content

Instantly share code, notes, and snippets.

View CocoaBob's full-sized avatar
😃

CocoaBob CocoaBob

😃
  • Montréal
View GitHub Profile
@CocoaBob
CocoaBob / TopViewController.swift
Created June 26, 2024 15:55
Swift get top view controller
// MARK: Find top view controller
extension UIViewController {
func topViewController(_ base: UIViewController?, _ nonPresented: Bool = false) -> UIViewController? {
if let nav = base as? UINavigationController {
return topViewController(nav.visibleViewController, nonPresented)
}
if let tab = base as? UITabBarController {
if let selected = tab.selectedViewController {
return topViewController(selected, nonPresented)
@CocoaBob
CocoaBob / PCX.swift
Created January 21, 2023 04:46
Get UIImage from PCX data, supports both monochrome and color formats, need to install `pod "BinaryDataScanner", '1.0.3'`. Ref: https://github.com/actumn/playground/tree/master/swift/swift_load_PCX
import Foundation
import UIKit
struct PCXhead {
var identity: UInt8 = 0
var pcxver: UInt8 = 0
var compression: UInt8 = 0
var bpp: UInt8 = 0
var minX: UInt16 = 0
var minY: UInt16 = 0