Skip to content

Instantly share code, notes, and snippets.

View muukii's full-sized avatar
✈️
We live in a twilight world.

Hiroshi Kimura muukii

✈️
We live in a twilight world.
View GitHub Profile
@WorldDownTown
WorldDownTown / KanaConverter.swift
Created December 18, 2019 04:51
Kanji to hiragana or katakana
View KanaConverter.swift
import Foundation
private extension CFStringTokenizer {
var hiragana: String { string(to: kCFStringTransformLatinHiragana) }
var katakana: String { string(to: kCFStringTransformLatinKatakana) }
private func string(to transform: CFString) -> String {
var output: String = ""
while !CFStringTokenizerAdvanceToNextToken(self).isEmpty {
output.append(letter(to: transform))
@danielmartin
danielmartin / BetterXcodeJumpToCounterpartSwift.org
Last active February 3, 2023 02:06
Add support for a better Xcode's Jump to Next Counterpart in Swift
View BetterXcodeJumpToCounterpartSwift.org

If you work on a Swift project that follows the Model-View-ViewModel (MVVM) architecture or similar, you may want to jump to counterpart in Xcode from your view to your model, and then to your view model. (ie. by using Ctrl+Cmd+Up and Ctrl+Cmd+Down).

You can do this in recent versions of Xcode by setting a configuration default.

From a terminal, just type this command and press Enter:

defaults write com.apple.dt.Xcode IDEAdditionalCounterpartSuffixes -array-add "ViewModel" "View"
@unnamedd
unnamedd / MacEditorTextView.swift
Last active November 23, 2023 09:24
[SwiftUI] MacEditorTextView - A simple and small NSTextView wrapped by SwiftUI.
View MacEditorTextView.swift
/**
* MacEditorTextView
* Copyright (c) Thiago Holanda 2020-2021
* https://twitter.com/tholanda
*
* MIT license
*/
import Combine
import SwiftUI
View CustomStringConvertible.swift
import Foundation
extension CustomStringConvertible {
var description: String {
var description: String = "\(type(of: self))("
let selfMirror = Mirror(reflecting: self)
for child in selfMirror.children {
if let propertyName = child.label {
@tclementdev
tclementdev / libdispatch-efficiency-tips.md
Last active November 27, 2023 18:24
Making efficient use of the libdispatch (GCD)
View libdispatch-efficiency-tips.md

libdispatch efficiency tips

The libdispatch is one of the most misused API due to the way it was presented to us when it was introduced and for many years after that, and due to the confusing documentation and API. This page is a compilation of important things to know if you're going to use this library. Many references are available at the end of this document pointing to comments from Apple's very own libdispatch maintainer (Pierre Habouzit).

My take-aways are:

  • You should create very few, long-lived, well-defined queues. These queues should be seen as execution contexts in your program (gui, background work, ...) that benefit from executing in parallel. An important thing to note is that if these queues are all active at once, you will get as many threads running. In most apps, you probably do not need to create more than 3 or 4 queues.

  • Go serial first, and as you find performance bottle necks, measure why, and if concurrency helps, apply with care, always validating under system pressure. Reuse

@lattner
lattner / async_swift_proposal.md
Last active November 23, 2023 04:43 — forked from oleganza/async_swift_proposal.md
Concrete proposal for async semantics in Swift
View async_swift_proposal.md

Async/Await for Swift

Introduction

Modern Cocoa development involves a lot of asynchronous programming using closures and completion handlers, but these APIs are hard to use. This gets particularly problematic when many asynchronous operations are used, error handling is required, or control flow between asynchronous calls gets complicated. This proposal describes a language extension to make this a lot more natural and less error prone.

This paper introduces a first class Coroutine model to Swift. Functions can opt into to being async, allowing the programmer to compose complex logic involving asynchronous operations, leaving the compiler in charge of producing the necessary closures and state machines to implement that logic.

@jverkoey
jverkoey / rubberBand.swift
Created November 30, 2016 06:55
Rubber banding in swift
View rubberBand.swift
public func rubberBand(value: CGFloat, min: CGFloat, max: CGFloat, bandLength: CGFloat) -> CGFloat {
if value >= min && value <= max {
// While we're within range we don't rubber band the value.
return value
}
if bandLength <= 0 {
// The rubber band doesn't exist, return the minimum value so that we stay put.
return min
@zwaldowski
zwaldowski / Activity.swift
Last active October 21, 2022 22:52
os_activity_t for Swift 3
View Activity.swift
//
// Activity.swift
//
// Created by Zachary Waldowski on 8/21/16.
// Copyright © 2016 Zachary Waldowski. Licensed under MIT.
//
import os.activity
private final class LegacyActivityContext {
@parmentf
parmentf / GitCommitEmoji.md
Last active December 5, 2023 22:24
Git Commit message Emoji
View GitCommitEmoji.md