Skip to content

Instantly share code, notes, and snippets.

View WayneWeiZhang's full-sized avatar

Wayne Zhang WayneWeiZhang

View GitHub Profile
import SwiftUI
extension CGPoint {
static func *(lhs: Self, rhs: CGFloat) -> Self {
.init(x: lhs.x * rhs, y: lhs.y * rhs)
}
}
// Idea: https://www.framer.com/showcase/project/lo2Qka8jtPXrjzZaPZdB/
@keith
keith / exclusivity.md
Last active May 6, 2021 00:47
The matrix of Xcode build settings to compiler flags for Swift memory exclusivity
  • Compiler flag: -enforce-exclusivity=<value>
  • Build setting: SWIFT_ENFORCE_EXCLUSIVE_ACCESS

Xcode 10.1 & Swift 4.2

  • Compiler default for non optimized builds if you pass no argument is the same as if you passed checked
  • Compiler default for optimized builds if you pass no argument is the same as if you passed unchecked
Configuration Compiler Flag Value Build Setting Description Build Setting Value Notes
@SheldonWangRJT
SheldonWangRJT / WWDC18-416.md
Last active April 11, 2021 09:45
WWDC18 Notes by Sheldon - Session 416 - iOS Memory Deep Dive

WWDC18 Notes - Session 416 - iOS Memory Deep Dive

All session list link: Here
Session Link: Here
Demo starts @ 25:30 in the video.
Download session slides: Here

This notes is written by Sheldon after watching WWDC18 session 416. You can find me with #iOSBySheldon in Github, Youtube, Facebook, etc.

@nadavrot
nadavrot / Matrix.md
Last active April 2, 2024 06:45
Efficient matrix multiplication

High-Performance Matrix Multiplication

This is a short post that explains how to write a high-performance matrix multiplication program on modern processors. In this tutorial I will use a single core of the Skylake-client CPU with AVX2, but the principles in this post also apply to other processors with different instruction sets (such as AVX512).

Intro

Matrix multiplication is a mathematical operation that defines the product of

@tclementdev
tclementdev / libdispatch-efficiency-tips.md
Last active April 16, 2024 01:02
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

void addMainThreadCheck(Class cls, SEL selector) {
#if DEBUG
void *symbol = dlsym(RTLD_DEFAULT, "__main_thread_add_check_for_selector");
if (!symbol) {
return;
}
void (*addCheck)(Class, SEL) = (__typeof__(addCheck))symbol;
addCheck(cls, selector);
#endif
}
As of iOS 11/macOS High Sierra, and only including ones in Foundation and CoreFoundation
Strings:
_NSCFString - a CFStringRef or CFMutableStringRef. This is the most common type of string object currently.
- May have 8 bit (ASCII) or 16 bit (UTF-16) backing store
_NSCFConstantString - a compile time constant CFStringRef, like you'd get with @"foo"
- May also be generated by dynamic string creation if matches a string in a pre-baked table of common strings called the StringROM
NSBigMutableString - an NSString backed by a CFStorage (https://github.com/opensource-apple/CF/blob/master/CFStorage.h) for faster handling of very large strings
NSCheapMutableString - a very limited NSMutableString that allows for zero-copy initialization. Used in NSFileManager for temporarily wrapping stack buffers.
@mikeash
mikeash / xcode.sh
Created September 15, 2017 17:07
Convince Xcode 9 not to smooth its source code font
#!/bin/bash
# Exit the script immediately on error
set -e
# We'll work in /tmp
cd /tmp
# Clone mach_override unless we already have it
if [ ! -d mach_override ]; then
@chriseidhof
chriseidhof / scanner.swift
Last active February 6, 2019 14:10
Scanning Sequences
import Foundation
// Alternatives to `Scanner` (before: `NSScanner`).
// A scanner only needs a way to peek and to move to the next token.
protocol ScannerProtocol {
associatedtype Token: Equatable
var peek: Token? { get }
mutating func moveToNextToken()
@myell0w
myell0w / KeyboardLayoutGuide.swift
Created July 19, 2017 14:53
A UILayoutGuide that follows the Keyboard on iOS
import Foundation
import UIKit
/// Used to create a layout guide that pins to the top of the keyboard
final class KeyboardLayoutGuide {
private let notificationCenter: NotificationCenter
private let bottomConstraint: NSLayoutConstraint