NSEdgeInsets capInsets = backgroundImage.capInsets;
NSSize imageSize = backgroundImage.size;
CALayer *layer = someView.layer;
layer.contents = backgroundImage;
layer.contentsScale = self.backingScaleFactor;
if (someView.isFlipped)
{
layer.contentsCenter = CGRectMake(
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
// The MIT License (MIT) | |
// | |
// Copyright © 2018 Tony Arnold (@tonyarnold) | |
// | |
// Permission is hereby granted, free of charge, to any person obtaining a copy | |
// of this software and associated documentation files (the "Software"), to deal | |
// in the Software without restriction, including without limitation the rights | |
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
// copies of the Software, and to permit persons to whom the Software is | |
// furnished to do so, subject to the following conditions: |
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 UIKit | |
public extension UIStoryboard { | |
public struct SceneDescriptor { | |
public let name: UIStoryboard.Name | |
public let identifier: UIStoryboard.SceneIdentifier | |
public init(name: UIStoryboard.Name, identifier: UIStoryboard.SceneIdentifier) { | |
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
enum JSON: Decodable, CustomStringConvertible { | |
var description: String { | |
switch self { | |
case .string(let string): return "\"\(string)\"" | |
case .number(let double): | |
if let int = Int(exactly: double) { | |
return "\(int)" | |
} else { | |
return "\(double)" | |
} |
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
// | |
// Copyright © 2017 Tony Arnold. | |
// | |
// This code is licensed under the MIT license. | |
// | |
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | |
// | |
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | |
// | |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERW |
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
// | |
// Copyright © 2017 Tony Arnold. All rights reserved. | |
enum CompoundValue<Element: Hashable> { | |
case distinct(Element) | |
case indistinct(Set<Element>) | |
case empty | |
var distinctValue: Element? { | |
switch self { |
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
extension RangeReplaceableCollectionType where Index : Comparable { | |
mutating func removeAtIndexes<S : SequenceType where S.Generator.Element == Index>(indexes: S) -> [Self.Generator.Element] { | |
return indexes.sort().lazy.reverse().map { removeAtIndex($0) } | |
} | |
} |
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
#ifndef MagicalRecordXcode7CompatibilityMacros_h | |
#define MagicalRecordXcode7CompatibilityMacros_h | |
#if __has_feature(nullability) | |
#define MR_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN | |
#define MR_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END | |
#define MR_nullable nullable | |
#define MR_nonnull nonnull | |
#define __MR_nullable __nullable | |
#define __MR_nonnull __nonnull |
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
RACSignal *textFieldDidFocus = [[[[view rac_valuesForKeyPath:@keypath(view, textField.window.firstResponder) observer:view] | |
takeUntil:view.rac_willDeallocSignal] filter:^BOOL(id value) { | |
@strongify(view); | |
return [view.textField.currentEditor isEqualTo:value]; | |
}] | |
mapReplace:view.textField]; |
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 Cocoa | |
class CocoaBotsDocument : NSDocument { | |
override func saveToURL(url: NSURL, ofType typeName: String, forSaveOperation saveOperation: NSSaveOperationType, completionHandler: (NSError!) -> Void) { | |
performAsynchronousFileAccessUsingBlock() { fileAccessCompletionHandler in | |
// I should be able to call: | |
super.saveToURL(url, ofType: typeName, forSaveOperation: saveOperation) { error in } |