Skip to content

Instantly share code, notes, and snippets.

@christianselig
christianselig / navigation-bar.swift
Created October 20, 2021 15:54
How to tweak the navigation bar color to make it consistent with system translucency when setting a color
if #available(iOS 15.0, *) {
let navigationBarAppearance = UINavigationBarAppearance()
navigationBarAppearance.configureWithDefaultBackground()
navigationBarAppearance.backgroundColor = UIColor(hexcode: "0C1019").withAlphaComponent(0.7)
navigationController!.navigationBar.standardAppearance = navigationBarAppearance
navigationController!.navigationBar.compactAppearance = navigationBarAppearance
navigationController!.navigationBar.scrollEdgeAppearance = navigationBarAppearance
} else {
navigationController!.navigationBar.barTintColor = UIColor(hexcode: "0C1019")
}
@khanlou
khanlou / ObjectStorage.swift
Created April 1, 2019 21:02
ObjectStorage 3.0
//
// ObjectStorage.swift
// Soroush Khanlou
//
// Created by Soroush Khanlou on 3/8/19.
// Copyright © 2019 Soroush Khanlou. All rights reserved.
//
import Foundation
@ole
ole / UIAlertController+TextField.swift
Last active September 13, 2022 14:20
A UIAlertController with a text field and the ability to perform validation on the text the user has entered while the alert is on screen. The OK button is only enabled when the entered text passes validation. More info: https://oleb.net/2018/uialertcontroller-textfield/
import UIKit
/// A validation rule for text input.
public enum TextValidationRule {
/// Any input is valid, including an empty string.
case noRestriction
/// The input must not be empty.
case nonEmpty
/// The enitre input must match a regular expression. A matching substring is not enough.
case regularExpression(NSRegularExpression)
@tclementdev
tclementdev / libdispatch-efficiency-tips.md
Last active March 11, 2024 22:57
Making efficient use of the libdispatch (GCD)

libdispatch efficiency tips

The libdispatch is one of the most misused API due to the way it was presented to us when it was introduced and for many years after that, and due to the confusing documentation and API. This page is a compilation of important things to know if you're going to use this library. Many references are available at the end of this document pointing to comments from Apple's very own libdispatch maintainer (Pierre Habouzit).

My take-aways are:

  • You should create very few, long-lived, well-defined queues. These queues should be seen as execution contexts in your program (gui, background work, ...) that benefit from executing in parallel. An important thing to note is that if these queues are all active at once, you will get as many threads running. In most apps, you probably do not need to create more than 3 or 4 queues.

  • Go serial first, and as you find performance bottle necks, measure why, and if concurrency helps, apply with care, always validating under system pressure. Reuse

// Swift's untyped errors are a goddam PiTA. Here's the pattern I use to try to work around this.
// The goal is basically to try to guarantee that every throwing function in the app throws an
// ApplicationError instead of some unknown error type. We can't actually enforce this statically
// But by following this convention we can simplify error handling
enum ApplicationError: Error, CustomStringConvertible {
// These are application-specific errors that may need special treatment
case specificError1
case specificError2(SomeType)
@fallroot
fallroot / manipulating-plist-in-macos-cli.md
Created August 7, 2017 06:08
Manipulating Property List in macOS Command Line

Manipulating Property List in macOS Command Line

Tools

⚠️ defaults 명령어는 홈 경로(~)는 인식하지만 상대 경로(., ..)는 인식하지 않는다.

@sooop
sooop / DragTableController.swift
Created February 9, 2017 06:07
NSTableView reordering row with drag and drop
//
// ViewController.swift
// DragTable
//
// Created by Anna Kim on 2017. 2. 9..
// Copyright © 2017년 Anna Kim. All rights reserved.
//
import Cocoa
@simme
simme / debounce-throttle.swift
Created December 20, 2016 10:04
Swift 3 debounce & throttle
//
// debounce-throttle.swift
//
// Created by Simon Ljungberg on 19/12/16.
// License: MIT
//
import Foundation
extension TimeInterval {
@zwaldowski
zwaldowski / Extra Logging for My Great App.mobileconfig
Last active January 19, 2024 00:35
Apple Configuration Profile for Logging in iOS 10 and macOS Sierra
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<!-- iOS 10, macOS Sierra, and friends bring a new logging subsystem that's
supposed to scale from the kernel, up to frameworks, and up to apps. It defaults
to a more regimented, privacy-focused approach that large apps and complex
systems need.
It, along with Activity Tracing introduced in iOS 8 and macOS Yosemite and the
Console app in macOS Sierra, hope to help you graduate from caveman debugging to
// Created by Sean Heber on 4/12/12.
#import <UIKit/UIKit.h>
// If you work with a designer who specifies color in sRGB using 102,0,204, this category makes it simpler to instantiate
// a color with that specification: [UIColor colorWithRGB:102:0:204 alpha:1.0];
@interface UIColor (RGB)
// NOTE: If you're using the extended sRGB color space, you'll want to use something other than UInt8 :-)
+ (UIColor *)colorWithRGB:(UInt8)r :(UInt8)g :(UInt8)b alpha:(CGFloat)alpha;