Skip to content

Instantly share code, notes, and snippets.

View kvdesa's full-sized avatar

Kévin Cardoso de Sá kvdesa

View GitHub Profile
@kvdesa
kvdesa / fallback_to_english_localization.md
Created January 12, 2022 19:13
Localization - Fallback to English

Overview

This code is a helper to always try to return the English version of a localized string when it's not found in the current selected language. This is usefull in scenarios where you don't have all Strings localized within the Localized.strings file for a specific language.

Explanation

When calling localized, the OS tries to find the String inside the Localizable.strings file for the current language. If not found, then it tries to search for the same String inside the English version of Localizable.strings. If that fails, then returns the String itself.

Code

@kvdesa
kvdesa / .enable_landscape_light_and_dark_previews.md
Last active July 14, 2022 19:46
Helpers to enable landscape, light and dark modes in preview.

Enable landscape in preview

Helper struct to enable landscape in preview.

Landscape {
    ContentView()
        .previewDevice("iPhone Xʀ")
        .landscape()
}
class CurvedView: UIView {
// MARK: - Constants
private enum Constants {
static let defaultCurvePercent: CGFloat = 0.1
static let defaultCurveSide = CurveSide.top
static let defaultCurveDirection = CurveDirection.inwards
}
@kvdesa
kvdesa / CancelBag.swift
Last active January 20, 2024 23:50
Combine class to manage cancellable instances instead of using a Set.
import Combine
import SwiftUI
final class CancelBag {
// MARK: - Properties
var subscriptions = Set<AnyCancellable>()
// MARK: - Actions
@kvdesa
kvdesa / add_custom_shortcuts_to_xcode.md
Last active June 26, 2024 15:08
Add custom commands with shortcuts to Xcode

Add Custom Commands with Shortcuts to Xcode

To add custom key bindings in Xcode, you have to edit this file (su privileges required): '/Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/Current/Resources/IDETextKeyBindingSet.plist

To facilitate this, just add the following code to .bash_profile/.zshrc:

# Add custom commands to Xcode.
# Run this every time Xcode updates.
function addCustomCommandsToXcode() {
@kvdesa
kvdesa / check_zombie_strings.md
Last active April 7, 2021 17:45
Check zombie strings in Xcode project

Check Zombie Strings in Xcode Projects

This script will search for zombie strings, i.e. strings not being used, in an Xcode project.

Original script here

Download it or create it yourself and add it to your user folder.

#!/bin/bash
@kvdesa
kvdesa / CustomNavBarDisplayViewController.swift
Last active July 20, 2022 21:09
ViewController with custom actions for showing/hiding the navigation bar and tab bar.
class CustomBarDisplayViewController: UIViewController {
// MARK: - Enums
enum NavBarDisplayAction {
case show
case hide
case none
}
@kvdesa
kvdesa / PhoneNumberFormatter.kt
Last active July 12, 2022 16:13
Android EditText mask for Brazilian and American phone numbers written in Kotlin.
package br.socialcondo.app.profile
import android.text.Editable
import android.text.TextWatcher
import android.widget.EditText
import java.lang.ref.WeakReference
/**
* Created by kevin on 31/01/18.
* Adapted from: