Skip to content

Instantly share code, notes, and snippets.

View Jeehut's full-sized avatar

Cihat Gündüz Jeehut

View GitHub Profile

Explicit Protocol Fulfillment

Introduction

This pitch introduces of a new keyword in front of declarations: conformance.

The conformance keyword means: "this declaration is intended by the programmer to fulfill a protocol requirement". Its presence is never required. However, when present, the program is ill-formed unless the declaration does match a protocol requirement.

For example:

@gohanlon
gohanlon / FocusStateTCA.swift
Last active April 4, 2022 20:16
TCA and new SwiftUI focus APIs from WWDC21
import Combine
import ComposableArchitecture
import SwiftUI
struct LoginFormState: Equatable {
var username: String = ""
var password: String = ""
var focusedField: Field?
enum Field: Hashable {
@tovkal
tovkal / Snapshotting+ImpreciseImage.swift
Created June 10, 2021 16:20
Workaround M1 swift-snapshot-testing
import UIKit
import SnapshotTesting
private let precision: Float = 0.9
// MARK: - UIViewController
extension Snapshotting where Value == UIViewController, Format == UIImage {
/// A snapshot strategy for comparing views based on pixel equality.
public static var impreciseImage: Snapshotting {
@Jeehut
Jeehut / DurationFormat.kt
Last active August 21, 2024 15:13
Localized duration formatting in Kotlin using APIs in Android 9+ with fallback to English on Android 8 and lower.
import android.icu.text.MeasureFormat
import android.icu.text.NumberFormat
import android.icu.util.MeasureUnit
import android.os.Build
import java.util.Locale
import kotlin.time.Duration
import kotlin.time.ExperimentalTime
import kotlin.time.days
import kotlin.time.hours
import kotlin.time.milliseconds
@Jeehut
Jeehut / SafeLocalizedStringKey.swift
Created July 19, 2020 17:00
Exploring safer localization workflows in SwiftUI ...
// Copyright © 2020 Flinesoft. All rights reserved.
import Foundation
import SwiftUI
public struct SafeLocalizedStringKey :
ExpressibleByStringLiteral,
ExpressibleByStringInterpolation,
ExpressibleByExtendedGraphemeClusterLiteral,
ExpressibleByUnicodeScalarLiteral,
@douglashill
douglashill / extract-most-common-localised-strings.swift
Last active November 5, 2024 09:18
Extracts the most common translations from Apple’s glossary files. Read more: https://douglashill.co/localisation-using-apples-glossaries/
#! /usr/bin/swift
// Douglas Hill, March 2020
/*
Extracts the most common translations from Apple’s glossary files.
This script helped with localisation for KeyboardKit (https://github.com/douglashill/KeyboardKit) by leveraging Apple’s existing translations.
More detail in the article at https://douglashill.co/localisation-using-apples-glossaries/
@douglashill
douglashill / extract-specific-localised-strings.swift
Last active November 5, 2024 09:17
Extracts specific localised strings from Apple’s glossary files. Read more: https://douglashill.co/localisation-using-apples-glossaries/
#! /usr/bin/swift
// Douglas Hill, March 2020
// This file is made available under the MIT license included at the bottom of this file.
/*
Extracts specific localised strings from Apple’s glossary files.
This script helped with localisation for KeyboardKit (https://github.com/douglashill/KeyboardKit) by leveraging Apple’s existing translations.
@douglashill
douglashill / explore-localisation-glossaries.swift
Last active November 5, 2024 09:16
Prints out translations from Apple’s glossary files matching text in a supplied English .strings file. Read more: https://douglashill.co/localisation-using-apples-glossaries/
#! /usr/bin/swift
// Douglas Hill, March 2020
// Prints out translations from Apple’s glossary files matching text in a supplied English .strings file.
// More detail in the article at https://douglashill.co/localisation-using-apples-glossaries/
import Foundation
let stringsSource = URL(fileURLWithPath: "PUT THE PATH TO YOUR ENGLISH .strings FILE HERE")
@Jeehut
Jeehut / AppPreferences.kt
Last active January 31, 2020 11:09
SharedPreferences wrapper in Kotlin: copy & paste the code into a new `AppPreferences.kt` file & follow the 4 TODO steps.
import android.content.Context
import android.content.Context.MODE_PRIVATE
import android.content.SharedPreferences
import androidx.core.content.edit
object AppPreferences {
private var sharedPreferences: SharedPreferences? = null
// TODO step 1: call `AppPreferences.setup(applicationContext)` in your MainActivity's `onCreate` method
fun setup(context: Context) {
@kieranb662
kieranb662 / XcodeKitHelpers.md
Last active October 31, 2024 15:05
[Xcode Editor Notes] Xcodekit Extensions to help make Xcode your own custom text editor.

Xcode Editor Notes

Suggestions

After adding the Extension target to a project

  1. Go to the menu bar -> Product -> Scheme -> Edit Scheme.
  2. Under the info tab change the executable dropdown menu to "Xcode.app".
  3. If you have a testing file add it to the "Arguments Passed On Launch" field under the Arguments tab.