Skip to content

Instantly share code, notes, and snippets.

@cute
cute / libdispatch-efficiency-tips.md
Created October 25, 2025 01:51 — forked from tclementdev/libdispatch-efficiency-tips.md
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

extension UISearchBar {
public var textField: UITextField? {
if #available(iOS 13, *) {
return searchTextField
}
let subViews = subviews.flatMap { $0.subviews }
guard let textField = (subViews.filter { $0 is UITextField }).first as? UITextField else {
return nil
}
return textField
@cute
cute / gist:8c08df76fdeae2d1146bc67e52a8b205
Created October 28, 2024 10:23 — forked from joaofranca/gist:3159618
gist 7: iOS - Customize UITableViewCell delete/move overlay views while editing
- (void)layoutSubviews{
[super layoutSubviews];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:0.0f];
for (UIView *subview in self.subviews) {
@cute
cute / BackdeployedWidgetAccentedRenderingMode.swift
Created October 15, 2024 08:03 — forked from ABashkirova/BackdeployedWidgetAccentedRenderingMode.swift
iOS 18 Widgets: Notes about updating the widget
import SwiftUI
import WidgetKit
@available(iOS, deprecated: 18.0, message: "use WidgetAccentedRenderingMode instead")
enum BackdeployedWidgetAccentedRenderingMode {
case accented
case accentedDesaturated
case desaturated
case fullColor
@cute
cute / BackdeployedWidgetAccentedRenderingMode.swift
Created October 15, 2024 08:03 — forked from ABashkirova/BackdeployedWidgetAccentedRenderingMode.swift
iOS 18 Widgets: Notes about updating the widget
import SwiftUI
import WidgetKit
@available(iOS, deprecated: 18.0, message: "use WidgetAccentedRenderingMode instead")
enum BackdeployedWidgetAccentedRenderingMode {
case accented
case accentedDesaturated
case desaturated
case fullColor
@cute
cute / is_connected_to_vpn.swift
Created December 30, 2023 11:16 — forked from azwan082/is_connected_to_vpn.swift
Check if iOS app is connected to VPN
func isConnectedToVpn() -> Bool {
let host = "www.example.com"
guard let reachability = SCNetworkReachabilityCreateWithName(nil, host) else {
return false
}
var flags = SCNetworkReachabilityFlags()
if SCNetworkReachabilityGetFlags(reachability, &flags) == false {
return false
}
let isOnline = flags.contains(.reachable) && !flags.contains(.connectionRequired)
@cute
cute / .gitignore
Created October 16, 2023 09:33 — forked from jirihnidek/.gitignore
Example of (Linux) client-server aplication using ECN bit in UDP packets.
.cproject
.project
build
@cute
cute / ios-default-fontsize-table.swift
Created October 15, 2023 11:52 — forked from christianklotz/ios-default-fontsize-table.swift
List of default font sizes for dynamic type
let defaultFontSizeTable = [
UIFontTextStyleHeadline: [
UIContentSizeCategoryAccessibilityExtraExtraExtraLarge: 26,
UIContentSizeCategoryAccessibilityExtraExtraLarge: 25,
UIContentSizeCategoryAccessibilityExtraLarge: 24,
UIContentSizeCategoryAccessibilityLarge: 24,
UIContentSizeCategoryAccessibilityMedium: 23,
UIContentSizeCategoryExtraExtraExtraLarge: 23,
UIContentSizeCategoryExtraExtraLarge: 22,
UIContentSizeCategoryExtraLarge: 21,
@cute
cute / openssl-build.sh
Created September 1, 2023 06:45 — forked from felix-schwarz/openssl-build.sh
Updated script that builds OpenSSL for OS X, iOS and tvOS. Bitcode enabled for iOS, tvOS. Updated to build for tvOS, use the latest SDKs, skip installing man pages (to save time), download the OpenSSL source over HTTPS, patch OpenSSL for tvOS to not use fork(). Currently requires Xcode7.1b or later (for the tvOS SDK).
#!/bin/bash
# This script downloads and builds the iOS, tvOS and Mac openSSL libraries with Bitcode enabled
# Credits:
# https://github.com/st3fan/ios-openssl
# https://github.com/x2on/OpenSSL-for-iPhone/blob/master/build-libssl.sh
# https://gist.github.com/foozmeat/5154962
# Peter Steinberger, PSPDFKit GmbH, @steipete.
# Felix Schwarz, IOSPIRIT GmbH, @felix_schwarz.
@cute
cute / endian.h
Created December 13, 2022 05:03 — forked from yinyin/endian.h
BSD/Linux-like <endian.h> for MacOS X
#ifndef __FINK_ENDIANDEV_PKG_ENDIAN_H__
#define __FINK_ENDIANDEV_PKG_ENDIAN_H__ 1
/** compatibility header for endian.h
* This is a simple compatibility shim to convert
* BSD/Linux endian macros to the Mac OS X equivalents.
* It is public domain.
* */
#ifndef __APPLE__