Skip to content

Instantly share code, notes, and snippets.

View vani2's full-sized avatar

Ivan Vavilov vani2

View GitHub Profile
//
// Diagrams.swift
// DiagramsSample
//
// Created by Chris Eidhof on 16.12.19.
// Copyright © 2019 objc.io. All rights reserved.
//
import SwiftUI
@chriseidhof
chriseidhof / sample.swift
Last active February 25, 2024 16:04
View Inspection
import SwiftUI
struct SizeKey: PreferenceKey {
static func reduce(value: inout CGSize?, nextValue: () -> CGSize?) {
value = value ?? nextValue()
}
}
struct ContentView: View {
@State var width: CGFloat? = nil
var body: some View {
@Alexander-Ignition
Alexander-Ignition / TextField.swift
Created November 2, 2018 11:30
UITextField keyboard language
class TextField: UITextField {
override var textInputMode: UITextInputMode? {
return UITextInputMode.activeInputModes.first(where: {
$0.primaryLanguage?.contains("ru") == true
})
}
}

Swift Asserts

Function name Condition In playgrounds and -Onone builds (the default for Xcode's Debug configuration) In -O builds (the default for Xcode's Release configuration) In -Ounchecked builds
assert 🔘 🔘
assertionFailure 🔘
precondition 🔘 🔘 🔘
preconditionFailure 🔘 🔘
fatalError 🔘 🔘 🔘
dispatchPrecondition 🔘 🔘 🔘
@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

/**
<#Короткое описание.#>
<#Длинное описание.#>
```
<#Пример использования#>
```
- Precondition: <#Предусловие.#>
- Warning: <#Предупреждение.#>
/*
Erica Sadun, http://ericasadun.com
*/
import Foundation
// --------------------------------------------------
// MARK: Foundation Interop
@natecook1000
natecook1000 / nshipster-new-years-2016.md
Last active July 10, 2018 19:24
NSHipster New Year's 2016

Greetings and salutations, NSHipsters!

As the year winds down, it's a tradition here at NSHipster to ask you, dear readers, to offer up your favorite tricks and tips from the past year as gifts to your fellow hipsters. With iOS 9, El Capitan, brand new watch- and tvOS's, and the open-sourcing of some minor Apple-related tech, there's bound to be lots to share.

Submit your favorite piece of Swift or @objc trivia, helpful hints, unexpected discoveries, useful workarounds, useless fascinations, or anything else you found cool this year. Just comment below!

If you need inspiration, try [the list from last year][2015], or [from the year before][2014], or [from the year before that][2013].