Skip to content

Instantly share code, notes, and snippets.

View asendra's full-sized avatar

Alberto Sendra asendra

View GitHub Profile
@lukeredpath
lukeredpath / Resizing.m
Created July 26, 2011 11:54
Resizing tableview to accomodate keyboard
- (void)resizeTableViewWithHeightOffset:(CGFloat)offsetHeight
animationDuration:(double)animationDuration
completion:(void (^)(BOOL))completionHandler
{
[UIView animateWithDuration:animationDuration animations:^{
CGRect frame = self.tableView.frame;
frame.size.height += offsetHeight;
self.tableView.frame = frame;
} completion:completionHandler];
}
@brentsimmons
brentsimmons / gist:5810992
Last active January 3, 2021 02:22
Detect a tap on a URL inside a UITextView. Note: the rs_links method isn't included -- you'll need something that takes text and returns an array of detected links. This gist just demonstrates walking through the UITextView characters.
@implementation UITextView (RSExtras)
static BOOL stringCharacterIsAllowedAsPartOfLink(NSString *s) {
/*[s length] is assumed to be 0 or 1. s may be nil.
Totally not a strict check.*/
if (s == nil || [s length] < 1)
return NO;
@JaviSoto
JaviSoto / gist:5906004
Last active June 27, 2023 10:25
Mark designated initializer at compile time
#define MSDesignatedInitializer(__SEL__) __attribute__((unavailable("Invoke the designated initializer `" # __SEL__ "` instead.")))
// Sample usage:
- (instancetype)initWithObject:(id)object;
- (instancetype)init MSDesignatedInitializer(initWithObject:); // <- This even gets auto-complete.
// Now calling init on this class would throw a warning.
@PadraigK
PadraigK / Widon't
Last active August 29, 2015 13:57
Quick and dirty implementation of Shaun Inman's 'Widont' in Cocoa
// Example:
//
// Widont makes the last space non-breaking
// so you don't end up with one word on its
// own.
//
// Widont makes the last space non-breaking
// so you don't end up with one word on
// its own.
//
@gdavis
gdavis / ThreadSafe.swift
Last active July 19, 2024 19:31
ThreadSafe is a property wrapper that can be used to control atomic access to the underlying property while allowing concurrent access to reading the value.
//
// ThreadSafe.swift
// GDICore
//
// Created by Grant Davis on 1/2/21.
// Updated to support `_modify` accessor on 12/5/21.
//
// Copyright © 2021 Grant Davis Interactive, LLC. All rights reserved.
//
import Foundation