Skip to content

Instantly share code, notes, and snippets.

View smaljaar's full-sized avatar
📱
🚀

Samuël Maljaars smaljaar

📱
🚀
View GitHub Profile
@elmolm
elmolm / UserDefaultsAndStructsExtension.swift
Last active August 6, 2020 14:15
Save and load structs and struct arrays in UserDefaults
import Foundation
extension UserDefaults {
open func setStruct<T: Codable>(_ value: T?, forKey defaultName: String){
let data = try? JSONEncoder().encode(value)
set(data, forKey: defaultName)
}
open func structData<T>(_ type: T.Type, forKey defaultName: String) -> T? where T : Decodable {
guard let encodedData = data(forKey: defaultName) else {
@DejanEnspyra
DejanEnspyra / IAPHandler.swift
Created July 18, 2017 18:13
[SWIFT] How to add In-App Purchases in your iOS app.
//
// IAPHandler.swift
//
// Created by Dejan Atanasov on 13/07/2017.
// Copyright © 2017 Dejan Atanasov. All rights reserved.
//
import UIKit
import StoreKit
@vinhnx
vinhnx / uicollectionview+fade.md
Last active February 24, 2022 18:58
Collection view cell fade as scrolling effect

// reference: https://stackoverflow.com/a/42705208/1477298

You can do a lot of fun stuff to collection views. I like to subclass UICollectionViewFlowLayout. Here is an example that fades the top and the bottom of the collection view based on distance from center. I could modify it to fade only the very edges but you should figure it after you look through the code.

import UIKit

class FadingLayout: UICollectionViewFlowLayout,UICollectionViewDelegateFlowLayout {

    //should be 0<fade<1
@ilyapuchka
ilyapuchka / StickyLayout.swift
Last active February 25, 2024 18:43
Really sticky collection view layout
// 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() {
super.init()
self.sectionFootersPinToVisibleBounds = true
self.sectionHeadersPinToVisibleBounds = true
}
@bartoszmajsak
bartoszmajsak / prepare-commit-msg.sh
Last active March 20, 2024 08:12
How to automatically prepend git commit with a branch name
#!/bin/bash
# This way you can customize which branches should be skipped when
# prepending commit message.
if [ -z "$BRANCHES_TO_SKIP" ]; then
BRANCHES_TO_SKIP=(master develop test)
fi
BRANCH_NAME=$(git symbolic-ref --short HEAD)
BRANCH_NAME="${BRANCH_NAME##*/}"