Skip to content

Instantly share code, notes, and snippets.

Tyler Fox smileyborg

Block or report user

Report or block smileyborg

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
smileyborg / InteractiveTransitionTableViewDeselection.m
Last active Jun 16, 2019
Animate table view deselection alongside interactive transition on iOS 11
View InteractiveTransitionTableViewDeselection.m
In iOS 11, interactive view controller transitions no longer scrub by setting the layer speed to zero
and changing the timeOffset. As a result of this change, implicit animations that occur in places like
-viewWillAppear: (called during an interactive transition) no longer end up “caught in” the animation.
To get the same behavior for table view row deselection as before, you can either use UITableViewController
which implements this for you, or you can implement it manually by deselecting the row in an alongside
animation for the transition (set up in -viewWillAppear: using the transition coordinator).
Here is an example implementation which correctly handles some of the more subtle corner cases:
smileyborg / SimulatedSlowLoadingImage.swift
Created Aug 5, 2017
Snippet showing how to create an NSItemProvider with a simulated delay for loading an image
View SimulatedSlowLoadingImage.swift
import UIKit
import MobileCoreServices
let image = UIImage() // your actual image
let itemProvider = NSItemProvider()
itemProvider.registerDataRepresentation(forTypeIdentifier: kUTTypeJPEG as String, visibility: .all) { (completionBlock) -> Progress? in
let unitsOfWork = 10 + Int64(arc4random_uniform(UInt32(10))) // 10 - 19 units
let progress = Progress.discreteProgress(totalUnitCount: unitsOfWork)
smileyborg / SelfSizingTableHeaderAndTableFooterViews.swift
Last active Sep 19, 2019
How to manually self-size UITableView tableHeaderView/tableFooterView in iOS 11
View SelfSizingTableHeaderAndTableFooterViews.swift
// For the best results, your tableHeaderView/tableFooterView should be a UITableViewHeaderFooterView with your content inside the contentView.
let tableHeaderView = UITableViewHeaderFooterView()
let fittingSize = CGSize(width: tableView.bounds.width - (tableView.safeAreaInsets.left + tableView.safeAreaInsets.right), height: 0)
let size = tableHeaderView.systemLayoutSizeFitting(fittingSize, withHorizontalFittingPriority: .required, verticalFittingPriority: .fittingSizeLevel)
tableHeaderView.frame = CGRect(origin: .zero, size: size)
tableView.tableHeaderView = tableHeaderView
// When you set this view to the tableHeaderView/tableFooterView on the table view, the table view will preserve the existing size of its frame.
// If you need to change the size, remove the tableHeaderView/tableFooterView, set a new frame on it, then re-set it on the table view again.

Keybase proof

I hereby claim:

  • I am smileyborg on github.
  • I am smileyborg ( on keybase.
  • I have a public key whose fingerprint is C460 F9E5 7D47 4E26 E24A 0F4A 7FCD A6ED 6139 A71A

To claim this, I am signing this object:

smileyborg / convert_imports.rb
Last active Jun 26, 2017
A script to convert textual imports to framework imports. Useful when converting static libraries to dynamic frameworks.
View convert_imports.rb
#!/usr/bin/env ruby
require 'set'
UMBRELLA_HEADER_PATH = ARGV[0] # The path to the umbrella header containing all the headers
SOURCE_ROOT_PATH = ARGV[1] # The path containing the source files to convert (will be recursively searched)
FRAMEWORK_NAME = File.basename(UMBRELLA_HEADER_PATH, ".*") # Assumes that the framework name is the same as the umbrella header filename (e.g. "MyFramework" for "MyFramework.h")
UMBRELLA_IMPORT_REGEX = /#import\s+<#{FRAMEWORK_NAME}\/.+\.h>/ # Matches "#import <FrameworkName/Header.h>"
FRAMEWORK_HEADER_REGEX = /(?<=<#{FRAMEWORK_NAME}\/).+\.h(?=>)/ # Matches "Header.h" in "<FrameworkName/Header.h>"
smileyborg / Xcode7Macros.h
Last active Apr 8, 2017
Backwards compatible macros for Objective-C nullability annotations and generics
View Xcode7Macros.h
* The following preprocessor macros can be used to adopt the new nullability annotations and generics
* features available in Xcode 7, while maintaining backwards compatibility with earlier versions of
* Xcode that do not support these features.
#if __has_feature(nullability)
# define __NULLABLE nullable
smileyborg / UIView+Orientation.h
Last active May 30, 2018
Migrating Rotation Code to iOS 8
View UIView+Orientation.h
// UIView+Orientation.h
#import <UIKit/UIKit.h>
// These macros should only be used if you MUST know the interface orientation for the device itself, for example when displaying a new UIWindow.
// This should be very rare; generally you should only look at the immediate parent view's size (or "view orientation" using the category below).
#define StatusBarOrientationIsPortrait UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation])
#define StatusBarOrientationIsLandscape UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])
smileyborg /
Last active Jun 4, 2019
Two scripts that can be used to detect evil merges in Git. See
# A shell script to provide a meaningful diff output for a merge commit that can be used to determine whether the merge was evil.
# The script should be run from outside the git repository, with two arguments:
# 1 - the directory of the git repository
# 2 - the SHA for the merge commit to inspect
# The script will output one file:
# - the merge redone fresh without any conflicts resolved, diff'ed to the actual merge
smileyborg / RJTableViewCell.m
Created Dec 3, 2014
View RJTableViewCell.m
/* Note that I have uncommented Line 9 to prevent constraint exceptions before the cells actually layout at their correct size. */
- (void)updateConstraints
if (!self.didSetupConstraints) {
// Note: if the constraints you add below require a larger cell size than the current size (which is likely to be the default size {320, 44}), you'll get an exception.
// As a fix, you can temporarily increase the size of the cell's contentView so that this does not occur using code similar to the line below.
// See here for further discussion:
self.contentView.bounds = CGRectMake(0.0f, 0.0f, 99999.0f, 99999.0f);
smileyborg / Example.swift
Last active Aug 29, 2015
PureLayout in Swift
View Example.swift
func setupConstraints()
let views: NSArray = [view1, view2, view3]
views.autoDistributeViewsAlongAxis(.Horizontal, withFixedSpacing: 10.0, insetSpacing: true, matchedSizes: false, alignment: .AlignAllTop)
// if you don't like creating an intermediate constant, the following works using Xcode 6.1 GM:
[view1, view2, view3].autoDistributeViewsAlongAxis(.Horizontal, withFixedSpacing: 10.0, insetSpacing: true, matchedSizes: false, alignment: .AlignAllTop)
You can’t perform that action at this time.