Skip to content

Instantly share code, notes, and snippets.

@sergdort
sergdort / TaskPublisher.swift
Last active June 12, 2021 11:51
Bridge between async await and Publisher.
@available(iOS 15.0, *)
struct TaskPublisher<Output>: Publisher{
typealias Failure = Never
let work: () async -> Output
init(work: @escaping () async -> Output) {
self.work = work
}
@atimca
atimca / iOS Interview Questions
Created April 14, 2020 14:49
iOS interview questions to interviewer from candidate
Question set for interviews
Developer
Tech
- [ ] How many projects do you have
- [ ] Which architectures approaches do you use
- [ ] Which swift version / legacy objc, c what are you going to do with it.
- [ ] Do you do layout in xibs or in code?
- [ ] What do you think about reactive programming (RxSwift)
@mariia-cherniuk
mariia-cherniuk / IfLetElseView.swift
Last active May 27, 2020 15:24
Nice little utility view that allows you handle optional values in your SwiftUI views
import SwiftUI
@available(iOS 13.0, *)
public struct IfLetElseView<Value, IfContent: View, ElseContent: View>: View {
private let value: Value?
private let ifContent: (Value) -> IfContent
private let elseContent: () -> ElseContent
public init(_ value: Value?,
@ViewBuilder ifContent: @escaping (Value) -> IfContent,
@propertyWrapper
public struct AnyProxy<EnclosingSelf, Value> {
private let keyPath: ReferenceWritableKeyPath<EnclosingSelf, Value>
public init(_ keyPath: ReferenceWritableKeyPath<EnclosingSelf, Value>) {
self.keyPath = keyPath
}
@available(*, unavailable, message: "The wrapped value must be accessed from the enclosing instance property.")
public var wrappedValue: Value {
@mluisbrown
mluisbrown / FixBTSound.applescript
Last active June 8, 2023 19:02
AppleScript to set macOS audio input device to "Internal Microphone"
-- Sets your audio input source to "Internal Microphone"
-- Frequently needed if you use bluetooth headpohones and
-- run the Xcode iOS simulator, which will often set your
-- headphones to be the input device, resulting in a drastic
-- decrease in sound quality, and making it mono
tell application "System Preferences" to activate
tell application "System Preferences"
reveal anchor "input" of pane id "com.apple.preference.sound"
end tell
@tclementdev
tclementdev / libdispatch-efficiency-tips.md
Last active April 26, 2024 10:15
Making efficient use of the libdispatch (GCD)

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 / TaskConcurrencyManifesto.md
Last active May 7, 2024 09:05
Swift Concurrency Manifesto
@maciekish
maciekish / resetXcode.sh
Created August 10, 2016 10:13
Reset Xcode. Clean, clear module cache, Derived Data and Xcode Caches. You can thank me later.
#!/bin/bash
killall Xcode
xcrun -k
xcodebuild -alltargets clean
rm -rf "$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang/ModuleCache"
rm -rf "$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang.$(whoami)/ModuleCache"
rm -rf ~/Library/Developer/Xcode/DerivedData/*
rm -rf ~/Library/Caches/com.apple.dt.Xcode/*
open /Applications/Xcode.app