Skip to content

Instantly share code, notes, and snippets.

View igrechuhin's full-sized avatar

Ilya Grechuhin igrechuhin

View GitHub Profile
@tclementdev
tclementdev / libdispatch-efficiency-tips.md
Last active April 10, 2025 19:06
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

@smileyborg
smileyborg / InteractiveTransitionCollectionViewDeselection.m
Last active November 3, 2024 16:25
Animate table & collection view deselection alongside interactive transition (for iOS 11 and later)
// UICollectionView Objective-C example
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSIndexPath *selectedIndexPath = [[self.collectionView indexPathsForSelectedItems] firstObject];
if (selectedIndexPath != nil) {
id<UIViewControllerTransitionCoordinator> coordinator = self.transitionCoordinator;
if (coordinator != nil) {
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
@alexathylane
alexathylane / iOS Universal Links Support Checklist.md
Last active August 8, 2024 09:35
iOS Universal Links Support Checklist
@evgeniyd
evgeniyd / NoteViewController.swift
Last active January 18, 2017 06:57
Swift 3: @autoclosure syntax to call functions upon UIAlertViewController's callbacks
/// The Medium artcile, discussing the approach
/// https://medium.com/@euginedubinin/swift-useful-autoclosure-when-presenting-uialertviewcontroller-b592d1643a50#.kx0fuqm1x
final class NoteViewController: UIViewController {
// ... set up target-action for an Edit UIButton somewhere here ...
private dynamic func handleEditButton() {
presentEditConfirmationDialog(onEdit: self.editArticle(),
onCancel: () ) /* assuming you have nothing to do upon cancellation */
@jbehrens94
jbehrens94 / SwiftStrategy.swift
Created January 17, 2017 11:09
StrategyExample
import Foundation
// First define the algorithm protocol.
protocol LoadBehaviour {
func execute() -> String
}
// Define the algorithms.
// Algorithm 1
class CoreDataManager: LoadBehaviour {
@leemorgan
leemorgan / Clamp.swift
Last active November 9, 2022 15:36
clamp() in Swift
///Returns the input value clamped to the lower and upper limits.
func clamp<T: Comparable>(value: T, lower: T, upper: T) -> T {
return min(max(value, lower), upper)
}
//-----------------------------------------------
// Example usage
let proposedIndex = 6
@leecade
leecade / 10.11_troubleshooting.md
Last active October 1, 2023 12:07
10.11_troubleshooting
@makmanalp
makmanalp / comparison.md
Last active June 10, 2024 14:24
Angular vs Backbone vs React vs Ember notes

Note: these are pretty rough notes I made for my team on the fly as I was reading through some pages. Some could be mildly inaccurate but hopefully not terribly so. I might resort to convenient fiction & simplification sometimes.

My top contenders, mostly based on popularity / community etc:

  • Angular
  • Backbone
  • React
  • Ember

Mostly about MVC (or derivatives, MVP / MVVM).

@arturlector
arturlector / ios-questions-interview.md
Last active March 3, 2025 15:02
Вопросы на собеседование iOS разработчика.

Вопросы на собеседование iOS разработчика (дополненное издание):

General:

  • Что такое полиморфизм?

  • Что такое *инкапсуляция? Что такое *нарушение инкапсуляции?

  • Чем абстрактный класс отличается от интерфейса?

  • Расскажите о паттерне MVC. Чем отличается пассивная модель от активной?

@irskep
irskep / getUIImageForRGBAData.swift
Created December 5, 2014 03:13
Convert RGBA bytes to UIImage in Swift
func getUIImageForRGBAData(#width: UInt, #height: UInt, #data: NSData) -> UIImage? {
let pixelData = data.bytes
let bytesPerPixel:UInt = 4
let scanWidth = bytesPerPixel * width
let provider = CGDataProviderCreateWithData(nil, pixelData, height * scanWidth, nil)
let colorSpaceRef = CGColorSpaceCreateDeviceRGB()
var bitmapInfo:CGBitmapInfo = .ByteOrderDefault;
bitmapInfo |= CGBitmapInfo(CGImageAlphaInfo.Last.rawValue)