This file contains 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
// | |
// Created by Tony Arnold on 4/03/2014. | |
// Copyright (c) 2014 The CocoaBots. All rights reserved. | |
// | |
#import "NSView+TCBAdditions.h" | |
#import <objc/runtime.h> | |
@implementation NSView (TCBAdditions) |
This file contains 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
public protocol MeasurementUnit { | |
// If we have one of this unit, how many millimeters is it? | |
class var asMillimeters: Double { get } | |
} | |
public class Inch : MeasurementUnit { | |
public class var asMillimeters: Double { | |
get { | |
return 25.4 | |
} | |
} |
This file contains 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 Foundation | |
/* | |
Lets suppose you have a class called "Action" which has to represent an user action in a drawing app. There are a fixed number of different actions: Delete, Add, Modify. Some of those action types have different properties. For example: | |
If the user adds something, the add action contains "what" the user has added and the "content" of the new object. | |
If the user modifies something, the modify action contains "what" has been edited, the "previousContent" and the "newContent". | |
So there are basically at least three different approaches how you can model that. Which one is the best? |
This file contains 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
// | |
// SSScrollView.h | |
// | |
/* | |
Get a delegate callback when the scroll view scrolls. | |
*/ | |
#import <Cocoa/Cocoa.h> |
This file contains 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
// In toolbarWillAddItem: create a new NSMenu | |
// set the delegate and add the menu as part of a NSMenuItem as menuFormRepresentation | |
- (void)menuNeedsUpdate:(NSMenu *)menu | |
{ | |
// clear out in case we can no longer provide this service | |
[menu removeAllItems]; | |
NSURL *fileURL = [self.document fileURL]; |
This file contains 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
// when setting the position of a layer, use this: | |
// layer.position = [ layer pixelAlignedPostionForPoint:<originalPoint> ] ; | |
@implementation CALayer (SetPositionPixelAligned) | |
-(CGPoint)pixelAlignedPositionForPoint:(CGPoint)p | |
{ | |
CGSize size = self.bounds.size ; | |
CGPoint anchorPoint = self.anchorPoint ; | |
This file contains 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
// Defines a yet undocumented method to add a warning if super isn't called. | |
#ifndef NS_REQUIRES_SUPER | |
#if __has_attribute(objc_requires_super) | |
#define NS_REQUIRES_SUPER __attribute((objc_requires_super)) | |
#else | |
#define NS_REQUIRES_SUPER | |
#endif | |
#endif |
This file contains 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
self.startButton.rac_command = [RACCommand command]; | |
self.stopButton.rac_command = [RACCommand command]; | |
self.resetButton.rac_command = [RACCommand command]; | |
static const CGFloat interval = 0.01; | |
__unsafe_unretained id weakSelf = self; | |
// Signal id -> Signal Signal Number | |
// Map each click of the start button to a signal that fires at our interval | |
// and stops when the stop button's clicked. | |
id<RACSignal> start = [self.startButton.rac_command map:^(id _) { |
This file contains 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
/// A statically typed view into a get-only property. | |
struct TypedGetPropertyView<T> { | |
/// The name of the property, as a string. | |
let name : String | |
/// The actual metatype of the property. | |
let metatype : T.Type | |
/// Get the value of the property. | |
func get() -> T |
This file contains 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
func unwrap<T1, T2>(optional1: T1?, optional2: T2?) -> (T1, T2)? { | |
switch (optional1, optional2) { | |
case let (.Some(value1), .Some(value2)): | |
return (value1, value2) | |
default: | |
return nil | |
} | |
} | |
func unwrap<T1, T2, T3>(optional1: T1?, optional2: T2?, optional3: T3?) -> (T1, T2, T3)? { |
OlderNewer