Skip to content

Instantly share code, notes, and snippets.

View vamsiac's full-sized avatar

Vamsi Anguluru vamsiac

View GitHub Profile
@dlo
dlo / Auto-layout-keyboard-adjustment.md
Last active February 26, 2021 07:33
How to adjust a view's height with Auto Layout when a keyboard appears or disappears in iOS 7.

This gist outlines how to resize a view when a keyboard appears using Auto Layout (there are a bunch of code samples out there that manually adjust the view's frame, but that's just so 2013). The method I outline below works universally on both iPhone and iPad, portrait and landscape, and is pretty darn simple.

Setting Up

The first thing to do is to define our containing view controller, the view, and the bottom constraint that we'll use to adjust its size.

Here's HeightAdjustingViewController.h. We don't need to expose any public properties, so it's pretty bare.

@oleganza
oleganza / async_swift_proposal.md
Last active May 12, 2023 10:06
Concrete proposal for async semantics in Swift

Async semantics proposal for Swift

Modern Cocoa development involves a lot of asynchronous programming using blocks and NSOperations. A lot of APIs are exposing blocks and they are more natural to write a lot of logic, so we'll only focus on block-based APIs.

Block-based APIs are hard to use when number of operations grows and dependencies between them become more complicated. In this paper I introduce asynchronous semantics and Promise type to Swift language (borrowing ideas from design of throw-try-catch and optionals). Functions can opt-in to become async, programmer can compose complex logic involving asynchronous operations while compiler produces necessary closures to implement that logic. This proposal does not propose new runtime model, nor "actors" or "coroutines".

Table of contents

@capttaco
capttaco / Fetchable.swift
Last active May 3, 2019 17:28
A utility protocol for custom NSManagedObjects that makes querying contexts simpler and more convenient. Requires Swift 2.
import CoreData
protocol Fetchable
{
typealias FetchableType: NSManagedObject
static func entityName() -> String
static func objectsInContext(context: NSManagedObjectContext, predicate: NSPredicate?, sortedBy: String?, ascending: Bool) throws -> [FetchableType]
static func singleObjectInContext(context: NSManagedObjectContext, predicate: NSPredicate?, sortedBy: String?, ascending: Bool) throws -> FetchableType?
static func objectCountInContext(context: NSManagedObjectContext, predicate: NSPredicate?) -> Int
@kharrison
kharrison / String.swift
Last active January 22, 2024 14:03
Swift String Playground Examples
// Swift Standard Librray - String
// Keith Harrison http://useyourloaf.com
// Import Foundation if you want to bridge to NSString
import Foundation
// ====
// Initializing a String
// ====
@jianminchen
jianminchen / SherlockAndAnagram9.cs
Created March 27, 2016 20:53
SherlockAndAnagram - use advanced C# programming expression - Lambda ?
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Solution
{
static void Main(String[] args)
{
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution */
@johnnyw
johnnyw / SKActionTransitionColor.swift
Created February 23, 2018 07:44
[SpriteKit] Custom SKAction to transition the fill/stroke color of an SKShapeNode.
import CoreGraphics
import SpriteKit
extension SKAction {
static func transitionStrokeColor(from: SKColor, to: SKColor, duration: TimeInterval) -> SKAction {
return transitionColor(from: from, to: to, duration: duration, fill: false)
}
static func transitionFillColor(from: SKColor, to: SKColor, duration: TimeInterval) -> SKAction {