Skip to content

Instantly share code, notes, and snippets.

Living, learning & making Apps better day by day

Alex Artemev bartleby

Living, learning & making Apps better day by day
View GitHub Profile
View do you even retain

Self в Swift и Objective-C

Дисклеймер: речь идёт об однопоточном коде, оставим ужасы параллельного исполнения за скобками. Также не рассматривается возможность overrelease.


Объект точно не ритейнится на время выполнения его метода, пруфы:

ha1f / CIFilter+Extension.swift
Last active Jun 7, 2020
View CIFilter+Extension.swift
// Created by はるふ on 2017/12/11.
// Copyright © 2017年 ha1f. All rights reserved.
import Foundation
import CoreImage
import AVFoundation
extension CIFilter {
ilyapuchka / StickyLayout.swift
Last active Jun 2, 2020
Really sticky collection view layout
View StickyLayout.swift
// The issue with sectionHeadersPinToVisibleBounds and sectionFootersPinToVisibleBounds is that they do not pin
// first header and last footer when bouncing. This layout subclass fixes that.
class StickyLayout: UICollectionViewFlowLayout {
override init() {
self.sectionFootersPinToVisibleBounds = true
self.sectionHeadersPinToVisibleBounds = true
View Cluster.swift
class Number /* class cluser */ {
class Int8: Number {
var value: Swift.Int8
init(_ value: Swift.Int8) { self.value = value }
class Int: Number {
var value: Swift.Int
init(_ value: Swift.Int) { self.value = value }
View LinearScale.swift
open class LinearScale {
var domain: [CGFloat]
var range: [CGFloat]
public init(domain: [CGFloat] = [0, 1], range: [CGFloat] = [0, 1]) {
self.domain = domain
self.range = range
pkuecuekyan / WKWebViewSizeToFit.swift
Last active Jun 5, 2020
Adjust height of WKWebView frame based on scrollHeight of the webView's content
View WKWebViewSizeToFit.swift
// Since the WKWebView has no sizeToFit() method, increase the frame height of the webView to
// match the height of the content's scrollHeight
// The WKWebView's `navigationDelegate` property needs to be set for the delegate method to be called
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
if webView.isLoading == false {
webView.evaluateJavaScript("document.body.scrollHeight", completionHandler: { [weak self] (result, error) in
if let height = result as? CGFloat {
cmoulton / Custom HTTP Headers with Swift and Alamofire.swift
Last active Mar 26, 2020
Custom HTTP Headers with Swift 3 or 4 and Alamofire 4.0-4.7: See for explanations
View Custom HTTP Headers with Swift and Alamofire.swift
// MARK: - Adding a header to a single request
func doRequestWithHeaders1() {
let headers: HTTPHeaders = [
"X-Mashape-Key": MY_API_KEY,
"Accept": "application/json"
Alamofire.request("", headers: headers)
.responseJSON { response in
andymatuschak /
Last active Jul 4, 2020
A composable pattern for pure state machines with effects (draft v3)

A composable pattern for pure state machines with effects

State machines are everywhere in interactive systems, but they're rarely defined clearly and explicitly. Given some big blob of code including implicit state machines, which transitions are possible and under what conditions? What effects take place on what transitions?

There are existing design patterns for state machines, but all the patterns I've seen complect side effects with the structure of the state machine itself. Instances of these patterns are difficult to test without mocking, and they end up with more dependencies. Worse, the classic patterns compose poorly: hierarchical state machines are typically not straightforward extensions. The functional programming world has solutions, but they don't transpose neatly enough to be broadly usable in mainstream languages.

Here I present a composable pattern for pure state machiness with effects,

mteece /
Last active Apr 15, 2020
List of NSTimeZone Abbreviations and Names (iOS 9.3.1)

NSTimeZone - Timezone Abbreviations ADT = "America/Halifax"; AKDT = "America/Juneau"; AKST = "America/Juneau"; ART = "America/Argentina/Buenos_Aires"; AST = "America/Halifax"; BDT = "Asia/Dhaka"; BRST = "America/Sao_Paulo"; BRT = "America/Sao_Paulo"; BST = "Europe/London";

shazron / gist:943736
Created Apr 27, 2011
About XCode 4 Project Template (How To Create Custom Project Template)
View gist:943736
XCode 4 Projects and Files Template Folder: /Developer/Library/Xcode/Templates
/Developer/Library/Xcode/Templates/Project Templates/Base/Other/Empty.xctemplate
/Developer/Library/Xcode/Templates/Project Templates/Base/Base.xctemplate
/Developer/Library/Xcode/Templates/Project Templates/Mac/Mac Base.xctemplate
/Developer/Library/Xcode/Templates/Project Templates/Mac/Application/Command Line Tool.xctemplate
/Developer/Library/Xcode/Templates/Project Templates/Mac/Application/Cocoa Application.xctemplate
You can’t perform that action at this time.