Skip to content

Instantly share code, notes, and snippets.

// Good
@IBAction func sideMenuClicked(_ sender: UIBarButtonItem) {
statusBarHidden = true
self.navigationController?.additionalSafeAreaInsets.top = 20
UIView.animate(withDuration: Constants.config_shortAnimTime) { () -> Void in
self.setNeedsStatusBarAppearanceUpdate()
}
}
@ollieatkinson
ollieatkinson / SVG.swift
Last active July 3, 2025 08:21
Utilise the private CoreSVG framework in Swift
import Darwin
import Foundation
import UIKit
// https://github.com/xybp888/iOS-SDKs/blob/master/iPhoneOS17.1.sdk/System/Library/PrivateFrameworks/CoreSVG.framework/CoreSVG.tbd
// https://developer.limneos.net/index.php?ios=17.1&framework=UIKitCore.framework&header=UIImage.h
@objc
class CGSVGDocument: NSObject { }
@simonbs
simonbs / childForStatusBarStyle.swift
Last active September 25, 2023 14:49
It seems that -childForStatusBarStyle: isn’t called on a UIViewController that is presented from a SwiftUI view using UIViewControllerRepresentable. Or am I doing something wrong? I came up with this *ugly* workaround that swizzles -childForStatusBarStyle: to return an associated object when present and uses the default implementation as fallback.
// We'll store a UIViewController as an associated object and don't want to store a strong reference to it.
private final class WeakBoxedValue<T: AnyObject>: NSObject {
private(set) weak var value: T?
init(_ value: T?) {
self.value = value
}
}
// Use associated objects to a UIViewController that should determine the status bar appearance.
//
// TransactionView.swift
//
// Created by Balazs Erdesz on 2021. 02. 23..
//
import SwiftUI
import Combine
struct TransactionView: View {

Minecraft on Apple Silicon

In this gist, you can find the steps to run Minecraft 1.16.4 natively on Apple Silicon (AS), without needing Rosetta 2 translation of the dependencies (mainly LWJGL and related libraries).

While it's possible to use a launcher like MultiMC to have a prettier way to run the game on AS, it requires installing even more dependencies (like QT) which take time and are difficult to distribute. Therefore, I've put together a command line-based launcher tool using a couple shell & Python scripts.

To get up and running quickly, follow the steps below. Otherwise, for more detail, watch my YouTube video.

Download my package

extension UIHostingController {
convenience public init(rootView: Content, ignoreSafeArea: Bool) {
self.init(rootView: rootView)
if ignoreSafeArea {
disableSafeArea()
}
}
func disableSafeArea() {
@aheze
aheze / DocumentPicker.swift
Last active April 11, 2022 11:09
UIDocumentPickerViewController example in Swift 5. Bug fixed version of this article: https://medium.com/flawless-app-stories/a-swifty-way-to-pick-documents-59cad1988a8a
//
// DocumentPicker.swift
import UIKit
import MobileCoreServices
protocol DocumentDelegate: class {
func didPickDocument(document: Document?)
}
@hkamran80
hkamran80 / canvas_lms.user.js
Last active August 22, 2020 04:05
Canvas LMS - Keystrokes
// ==UserScript==
// @name Canvas LMS - Keystrokes
// @namespace https://hkamran.com
// @version 1.0.1
// @description Snippets for the Canvas LMS
// @author H. Kamran
// @downloadUrl https://gist.github.com/hkamran80/8f0778b0f5379305674742682cb17b5e/raw/canvas_lms.user.js
// @updateUrl https://gist.github.com/hkamran80/8f0778b0f5379305674742682cb17b5e/raw/canvas_lms.user.js
// @match https://*.instructure.com/courses/*
// @grant none

How to play custom audio on Swift Playgrounds for iPad, using SwiftUI.

import AVFoundation
import SwiftUI
import PlaygroundSupport

struct SwiftUIAudioPlayerView: View {
    
    /// the audio player that will play your audio file. Can't be a local variable.
@rogerluan
rogerluan / String+Regex.swift
Created July 27, 2020 02:26
Handy Regex utility to find and replace matching groups in Swift.
extension String {
/// Finds matching groups and replace them with a template using an intuitive API.
///
/// This example will go through an input string and replace all occurrences of "MyGreatBrand" with "**MyGreatBrand**".
///
/// let regex = try! NSRegularExpression(pattern: #"(MyGreatBrand)"#) // Matches all occurrences of MyGreatBrand
/// someMarkdownDocument.replaceGroups(matching: regex, with: #"**$1**"#) // Surround all matches with **, formatting as bold text in markdown.
/// print(someMarkdownDocument)
///
/// - Parameters: