Skip to content

Instantly share code, notes, and snippets.

View leviathan's full-sized avatar

Jörg Polakowski leviathan

  • Lund, Sweden
  • 03:48 (UTC +02:00)
View GitHub Profile
@leviathan
leviathan / DiscoverAppModuleClasses.m
Last active August 29, 2015 14:05
Object discovery
#import <objc/runtime.h>
- (NSArray *)discoverAppModuleClasses
{
NSMutableArray *appModuleClasses = [NSMutableArray array];
// Integrate all classes which comply to the provider protocol
unsigned int count = 0;
Class *classList = objc_copyClassList(&count);
for (NSUInteger index = 0; index < count; index++)
@leviathan
leviathan / NSObject+ClassMethodList.m
Created January 20, 2016 09:10
Find properties as strings of a Class
/**
* Determines the properties of @c className and returns list of these properties as strings.
* The method will iterate through @c className superclass hierarchy and fetch the properties from
* the superclass hierarchy as well.
*
* @return the list of properties found on @c className
*/
- (NSOrderedSet<NSString *> *)getMethodListForClass:(Class)className
{
NSMutableOrderedSet<NSString *> *propertiesList = [NSMutableOrderedSet orderedSet];
@leviathan
leviathan / force-reset-git-branch
Created October 18, 2017 13:01
Force reset git branch
git checkout develop
git pull origin develop
git checkout stage
git reset --hard develop
git push origin stage --force-with-lease
@leviathan
leviathan / xcode-utils.md
Last active August 29, 2025 19:44
xcrun cheat sheet

Environment Info

xcode-select --print-path
xcodebuild -version
swift --version
swift build --version
pkgutil --pkg-info=com.apple.pkg.CLTools_Executables | grep version   // Check Xcode Command-Line-Tools Version
@leviathan
leviathan / UIImage+FileDump.swift
Last active January 22, 2020 07:35
UIImage quick file dump
/// Quickly dump a UIImage from memory into a tmp file.
var image: UIImage?
// ...
let imageFilePath = NSTemporaryDirectory() + "\(Date().timeIntervalSince1970).png"
try? image.pngData()!.write(to: URL(fileURLWithPath: imageFilePath))
print("Saved turn-by-turn advice image to: \(imageFilePath)")
@leviathan
leviathan / homebrew.md
Last active March 22, 2022 10:52
Cheat sheet: homebrew

Show Terminal config variables

$ env
TERM_PROGRAM=Apple_Terminal
SHELL=/usr/local/bin/zsh
TERM=xterm-256color
TMPDIR=/var/folders/l4/kb9wf5dn5g31y8ctr6fj_f9c0000gn/T/
...
@leviathan
leviathan / markdown-snippets.md
Last active February 21, 2020 15:22
markdown snippets

Table

Before After
before after

raw

| Before | After |

Swift code snippets

Make every view scollable

You can constrain the content, the UIStackView, to the contentLayoutGuide top, bottom, leading, and trailing to define the scrollable area. You can then constrain the UIStackView’s width to the frameLayoutGuide so that it only scrolls vertically. That’s it—your content can now scroll as it shrinks or grows!

UIView update constraints

final class SomeView: UIView {
@leviathan
leviathan / ScopedPublisher.swift
Last active November 10, 2020 08:17
A Combine publisher "wrapper", that receives on a specific Scheduler.
import Foundation
import UIKit
import Combine
import PlaygroundSupport
/// The `ScopedReceivePublisher` modifies any returned `Publisher` property of `V` to receive
/// published elements on the specified `Scheduler`.
///
/// Usage:
/// ```
@leviathan
leviathan / ObservableViewController.swift
Created January 7, 2021 16:46
ObservableViewController - functional reactive View Lifecycle handling with Combine
import Combine
import UIKit
/// View controller, that publishes events for it's `view`'s lifecycle,
/// and allows type safe access to it's main `UIView`.
class ObservableViewController<V: UIView>: UIViewController {
typealias LifecycleEvent = (view: V, animated: Bool)
/// Broadcasts event after the controller's view is loaded, e.g. `viewDidLoad()`.