Skip to content

Instantly share code, notes, and snippets.

View Jeehut's full-sized avatar

Cihat Gündüz Jeehut

View GitHub Profile
@loganwright
loganwright / Shell.swift
Last active November 12, 2016 10:46
Call shell commands from Swift
func shell(input: String) -> (output: String, exitCode: Int32) {
let arguments = split(input, maxSplit: Int.max, allowEmptySlices: true) {
$0 == " "
}
let task = NSTask()
task.launchPath = "/usr/bin/env"
task.arguments = arguments
task.environment = [
"LC_ALL" : "en_US.UTF-8",
@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) {
@ashevin
ashevin / NSPredicate+extensions.swift
Created October 24, 2017 08:49
NSPredicate+extensions
//
// NSPredicate+extensions.swift
// CoreDataManager
//
// Created by Avi Shevin on 23/10/2017.
// Copyright © 2017 Avi Shevin. All rights reserved.
//
import Foundation
@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 {
@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 {
@yoichitgy
yoichitgy / mergegenstrings.py
Last active July 9, 2022 23:59
A script to generate .strings file for .swift, .m, .storyboard and .xib files by genstrings and ibtool commands, and merge them with existing translations.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Localize.py - Incremental localization on XCode projects
# João Moreno 2009
# http://joaomoreno.com/
# Modified by Steve Streeting 2010 http://www.stevestreeting.com
# Changes
# - Use .strings files encoded as UTF-8
@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,
@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.
@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")
@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.