This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (CGPoint)targetContentOffsetForProposedContentOffset:(CGPoint)proposedContentOffset withScrollingVelocity:(CGPoint)velocity { | |
CGFloat offsetAdjustment = MAXFLOAT; | |
CGFloat horizontalCenter = proposedContentOffset.x + (CGRectGetWidth(self.collectionView.bounds) / 2.0); | |
CGRect targetRect = CGRectMake(proposedContentOffset.x, 0.0, self.collectionView.bounds.size.width, self.collectionView.bounds.size.height); | |
NSArray *attributesArray = [super layoutAttributesForElementsInRect:targetRect]; | |
for (UICollectionViewLayoutAttributes *layoutAttributes in attributesArray) { | |
CGFloat itemHorizontalCenter = layoutAttributes.center.x; | |
if (ABS(itemHorizontalCenter - horizontalCenter) < ABS(offsetAdjustment)) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"$schema": "http://json-schema.org/draft-04/schema#", | |
"title": "Event Response", | |
"type": "object", | |
"properties": { | |
"id": { | |
"description": "Unique identifier for an event", | |
"type": "integer" | |
}, | |
"title": { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// CustomTabBar.swift | |
// welbe | |
// | |
// Created by Ben Norris on 12/8/15. | |
// Copyright © 2015 O.C. Tanner Corporation. All rights reserved. | |
// | |
import UIKit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ListViewController.swift | |
// welbe | |
// | |
// Created by Ben Norris on 12/3/15. | |
// Copyright © 2015 O.C. Tanner Corporation. All rights reserved. | |
// | |
import UIKit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GBClock { | |
var referenceDate = NSDate(timeIntervalSinceReferenceDate: 0) | |
var referenceDateInterval: NSTimeInterval { referenceDate.timeIntervalSinceReferenceDate } | |
func currentTime() → NSDate { | |
return NSDate(timeIntervalSinceNow: referenceDateInterval) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol Preferences: class { | |
var showNames: Bool { get set } | |
func registerDefaults(registrar: Preferences -> Void) | |
} | |
private class DefaultPreferenceValues: Preferences { | |
var showNames = false | |
func registerDefaults(registrar: Preferences -> Void) { | |
fatalError("The registrar cannot register defaults") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct FlagEmoji { | |
private static let regionalIndicatorA: UInt32 = 0x1F1E6 | |
| |
enum Error: ErrorType { | |
case ExpectedOnlyAZ | |
} | |
| |
private static func toRegionalIndicator(scalar: UnicodeScalar) throws -> UnicodeScalar { | |
let offset: UInt32 | |
switch scalar { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CollectionViewController: UIViewController { | |
... | |
func snapToCenter() { | |
let centerPoint = view.convertPoint(view.center, toView: collectionView) | |
guard let centerIndexPath = collectionView.indexPathForItemAtPoint(centerPoint) | |
collectionView.scrollToItemAtIndexPath(centerIndexPath, atScrollPosition: .CenteredHorizontally, animated: true) | |
} | |
... | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Security | |
/// A wrapper around the Keychain API. | |
public class Keychain { | |
private let name: String | |
private let accessGroup: String? | |
public init(name: String, accessGroup: String? = nil) { | |
self.name = name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// From Bart Whiteley | |
public protocol UnmarshalingFactory: Marshal.ValueType { | |
associatedtype ConvertibleType = Self | |
static func createFromObject(object: MarshaledObject) throws -> ConvertibleType | |
} | |
extension UnmarshalingFactory { | |
public static func value(object: Any) throws -> ConvertibleType { |