Skip to content

Instantly share code, notes, and snippets.

View TosinAF's full-sized avatar
🧢

Tosin Afolabi TosinAF

🧢
View GitHub Profile
@marcpalmer
marcpalmer / FrameCapture.swift
Created March 6, 2023 10:42
Modifiers to easily capture and store view geometry in state.
//
// FrameCapture.swift
// FrameCapture
//
// Created by Marc Palmer on 31/03/2020.
//
// This is free and unencumbered software released into the public domain.
//
// Anyone is free to copy, modify, publish, use, compile, sell, or
// distribute this software, either in source code form or as a compiled
import _Concurrency
import Combine
import Dispatch
import Foundation
// MARK: General
struct SomeError: Error {}
extension AnyPublisher {
@jasdev
jasdev / ScrimLoader.swift
Last active April 19, 2024 03:47
Rough sketch of Arc’s scrim loading view.
import SwiftUI
/**
### Exercises for the viewer
- Phase interrupt handling.
- Use Swift concurrency.
- Color scheme awareness.
- Rework animations to be more spring-like à la what shipped in `0.90.0`.
@tclementdev
tclementdev / libdispatch-efficiency-tips.md
Last active July 12, 2024 03:33
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

@niw
niw / ios11_uinavigationbar_behavior.md
Last active January 3, 2024 11:35
A note of my observation about iOS 11 UINavigationBar behavior.

UINavigationBar on iOS 11

NOTE This note is written based on Xcode version 9.0 beta 6 (9M214v) and its simulator binary.

iOS 11 changes UINavigationBar a lot, not just only for its large title, but also the internal view hierarchy and lay outing views are changed. This is a small note about UINavigationBar behavior on iOS 11, mainly focusing on migrating the application to iOS 11.

Lay outing views

UINavigationBar has been using manual lay outing until iOS 10, so all its content views like titleView has been directly child view of the UINavigationBar. However, since iOS 11, it is using auto layout with bunch of layout guides to lay out its content views in its own internal container view, _UINavigationBarContentView.

@joshavant
joshavant / AppDelegate.swift
Last active June 11, 2016 15:11
Optimal Push Notification Pattern
class AppDelegate: UIResponder, UIApplicationDelegate {
private var currentUserNotificationTypes: UIUserNotificationType = .None
private func processUpdatedUserNotificationSettings(application: UIApplication, currentUserNotificationSettings notificationSettings: UIUserNotificationSettings?) {
let newUserNotificationTypes: UIUserNotificationType = notificationSettings?.types ?? .None
// only performs actions if the current value has a delta with the new value
if currentUserNotificationTypes.contains(.Alert) != newUserNotificationTypes.contains(.Alert) {
self.currentUserNotificationTypes = newUserNotificationTypes
@soffes
soffes / SpaceView-iOS.swift
Last active June 29, 2017 19:11
Handy utility view when working with UIStackView
import UIKit
/// Space view intented to be used with auto layout.
/// Similar to UIStackView, setting a background color is not supported.
final class SpaceView: UIView {
// MARK: - Properties
private let contentSize: CGSize
@JadenGeller
JadenGeller / ConstraintBuilder.swift
Last active December 24, 2015 22:49
Interpolated Visual Constraint Language
// Example
let blueView = UIView()
blueView.backgroundColor = UIColor.blueColor()
blueView.translatesAutoresizingMaskIntoConstraints = false
let greenView = UIView()
greenView.backgroundColor = UIColor.greenColor()
greenView.translatesAutoresizingMaskIntoConstraints = false
@zats
zats / WMLViewDebugging.m
Last active June 28, 2016 01:46
Improving View Debugging in Xcode by showing ViewController class this view belongs to http://blog.zats.io/2015/06/16/improving-view-debugging-in-xcode/
#ifdef DEBUG
#import "WMLSwizzler.h"
static SEL wml_loadViewSEL;
static void wml_swizzleLoadViewForClass(Class class) {
typedef void(*load_view_t)(id, SEL);
__block load_view_t loadView = (load_view_t)[class S_replaceInstanceMethod:wml_loadViewSEL withBlock:^(UIViewController *self){
loadView(self, wml_loadViewSEL);
@Tokuriku
Tokuriku / Count lines of code in Xcode project
Last active June 30, 2024 21:09 — forked from ccabanero/Count lines of code in Xcode project
Count lines of code in SWIFT Xcode project
1. Open Terminal
2. cd to your Xcode project
3. Execute the following when inside your target project:
find . -name "*.swift" -print0 | xargs -0 wc -l