Skip to content

Instantly share code, notes, and snippets.

View robb's full-sized avatar

Robb Böhnke robb

View GitHub Profile
// MTLManagedObjectAdapter.m
- (NSPredicate *)uniquingPredicateForModel:(MTLModel<MTLManagedObjectSerializing> *)model {
NSSet *propertyKeys = nil;
if ([self.modelClass respondsToSelector:@selector(propertyKeysForManagedObjectUniquing)]) {
propertyKeys = [self.modelClass propertyKeysForManagedObjectUniquing];
}
NSPredicate *predicate = nil;
for (NSString *propertyKey in propertyKeys) {

Mantle

Mantle makes it easy to write a simple model layer for your Cocoa or Cocoa Touch application.

Getting Started

To start building the framework, clone this repository and then run script/bootstrap. This will automatically pull down any dependencies.

Running 136 tests:
........................................................................................................................................
# ----- XCode (OCUnit) Test Output --------------------
Test Case '-[AsyncSpecTest testAsyncSpec]' started.
Test Case '-[AsyncSpecTest testAsyncSpec]' passed (0.036 seconds).
Test Case '-[AsyncSpecTest2 testBeforeAllAndAfterAllHooks]' started.
Test Case '-[AsyncSpecTest2 testBeforeAllAndAfterAllHooks]' passed (0.000 seconds).
@robb
robb / gist:8777652
Created February 3, 2014 01:26
boolean operators for matchers
@interface FooTests : XCTestCase
@end
@implementation FooTests
- (void)testAnd {
expect(@"foo")
.to.beKindOfClass(NSString.class)
.and.equal(@"foo");
@robb
robb / underscore.m
Last active August 29, 2015 13:56 — forked from rnapier/underscore.m
// No blocks-as-properties, just classic arguments
NSArray *tweets = [[[[[Underscore
array:results]
filter:Underscore.isDictionary]
reject:^(NSDictionary *tweet) {
return [tweet[@"iso_language_code"] isEqualToString:@"en"];
}]
map:^(NSDictionary *tweet) {
NSString *name = tweet[@"from_user_name"];
Inbefore: im wald, morgen
import Prelude
public struct Lens<A, B> {
private let get: A -> B
private let set: (A, B) -> A
public init(get: A -> B, set: (A, B) -> A) {
self.get = get
self.set = set
}
import Foundation
typealias JSONDictionary = [String: AnyObject]
/// Attempts to load a data from a given URL.
func loadData(URL: NSURL) -> Either<NSError, NSData> {
if let data = NSData(contentsOfURL: URL) {
return Either.Right(Box(data))
} else {
// In a real world scenario, we'd have a more useful error :-)
{
"name": "SBJson",
"version": "4.0.2",
"license": {
"type": "BSD",
"text": " Copyright (C) 2007-2015 Stig Brautaset. All rights reserved.\n\n Redistribution and use in source and binary forms, with or without\n modification, are permitted provided that the following conditions are met:\n\n * Redistributions of source code must retain the above copyright notice, this\n list of conditions and the following disclaimer.\n * Redistributions in binary form must reproduce the above copyright notice,\n this list of conditions and the following disclaimer in the documentation\n and/or other materials provided with the distribution.\n * Neither the name of the author nor the names of its contributors may be used\n to endorse or promote products derived from this software without specific\n prior written permission.\n\n THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\n AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT L
@robb
robb / Example.m
Last active January 9, 2024 14:38
A macro to convert nullable references to nonnull references while triggering an assert if the expression is actually true. Think of this as unsafe unwrap for Objective-C.
NS_ASSUME_NONNULL_BEGIN
void Log(NSString *foo) {
NSLog(@"%@", foo);
}
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSDictionary *stuff = @{
@"a": @"Test"