Skip to content

Instantly share code, notes, and snippets.

View brunogama's full-sized avatar

Bruno da Gama Porciuncula brunogama

View GitHub Profile
@NikKovIos
NikKovIos / UIButton+ActionBlock.swift
Last active October 1, 2020 18:16
Add the block closure to the UIButton.
/// Block for addTarget
extension UIControl {
public typealias UIControlActionBlock = (_ sender: UIControl) -> Void
public class UIControlClosureWrapper {
let owner: UIControl
let actionBlock: UIControlActionBlock
let event: UIControlEvents
@parrots
parrots / AsyncOperation.swift
Last active May 17, 2021 10:44
A Swifty version of an AsyncOperation which solves two common problems I ran into. (see comment below for issues addressed)
//
// AsyncOperation.swift
// Slopes
//
import Foundation
class AsyncOperation: Operation {
private let stateLock = NSLock()
private var observers: [NSKeyValueObservation] = [NSKeyValueObservation]()
@davedelong
davedelong / build_script.sh
Created November 22, 2018 18:12
Auto-increment build numbers in release mode
# Automatically increment the CFBundleVersion in release builds
config=${CONFIGURATION}
if [ "${config}" = "Release" ]; then
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${PROJECT_DIR}/${INFOPLIST_FILE}")
buildNumber=$(($buildNumber + 1))
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "${PROJECT_DIR}/${INFOPLIST_FILE}"
else
echo "info: Skipping build number incrementation in ${config} mode"
@yusuke024
yusuke024 / ViewController.swift
Created November 16, 2018 03:15
Recording video with AVAssetWriter
import UIKit
import AVFoundation
class ViewController: UIViewController {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
switch AVCaptureDevice.authorizationStatus(for: .video) {
case .notDetermined:
@Tras2
Tras2 / cloudflare-ddns-update.sh
Last active August 18, 2025 04:46
A bash script to update a Cloudflare DNS A record with the external IP of the source machine
#!/bin/bash
# A bash script to update a Cloudflare DNS A record with the external IP of the source machine
# Used to provide DDNS service for my home
# Needs the DNS record pre-creating on Cloudflare
# Proxy - uncomment and provide details if using a proxy
#export https_proxy=http://<proxyuser>:<proxypassword>@<proxyip>:<proxyport>
# Cloudflare zone is the zone which holds the record
@CassiusPacheco
CassiusPacheco / TextContentType.swift
Last active October 8, 2019 20:25
(iOS 12 compatible) UITextField extension to handle `textContentType` without dealing with iOS version checking.
//
// TextContentType.swift
// textfield
//
// Created by Cassius Pacheco on 5/6/18.
// Copyright © 2018 Cassius Pacheco. All rights reserved.
//
import UIKit
@ahmedk92
ahmedk92 / UIButton+Blocks.swift
Created March 13, 2018 07:58
Closure syntax for UIButton's addTarget
import UIKit
extension UIButton {
typealias BlockType = (UIButton) -> ()
private static var controlStatesBlockKey = "controlStatesBlockKey"
func add(block: @escaping BlockType, forControlEvents controlEvents: UIControlEvents) {
UIButton.controlStatesBlockKey += "\(controlEvents)"
var blocks = (objc_getAssociatedObject(self, &UIButton.controlStatesBlockKey) as? [BlockType]) ?? []
blocks.append(block)
@gokselkoksal
gokselkoksal / Channel.swift
Last active September 16, 2022 03:53
Channel implementation
public class Channel<Value> {
private class Subscription {
weak var object: AnyObject?
private let notifyBlock: (Value) -> Void
private let queue: DispatchQueue
var isValid: Bool {
return object != nil
@Siemian
Siemian / UIView+Constraints.swift
Last active December 31, 2024 21:06
UIView extension for creating NSLayoutConstraints
//
// UIView+Constraints.swift
// CiLabs
//
// Copyright © 2019 Netguru.co. All rights reserved.
//
import UIKit
typealias Constraint = (_ layoutView: UIView) -> NSLayoutConstraint
@bramus
bramus / fix.md
Last active May 20, 2018 19:47
Fixing the XCode 9.x Simulator 3D/Map Performance issue

Got a slow/unresponsive Simulator with XCode 9.x?

You're most likely using some kind of 3D or Native Maps in your App then, no? Awaiting XCode 9.1 (which contains a fix) here's a workaround which replaces the bundled OpenGLES.framework with the version from XCode 9.0 beta 3.

Please do note …

⚠️ Installing frameworks/binaries from unfamiliar/untrusted resources always involves some risk. I can only say that I’ve been using the linked version without any issues. Your mileage may vary.

Instructions