• Stars
    star
    555
  • Rank 80,213 (Top 2 %)
  • Language
    Objective-C
  • License
    MIT License
  • Created almost 14 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A set of Objective-C additions and macros that helps you write code more quickly.

ConciseKit

A set of Objective-C additions and macros that lets you to write code more quickly.

Pull requests are welcome!

USAGE

Use CocoaPods

dependency 'ConciseKit', '~> 0.1.2'

or

  1. Copy files under src/ to your project.
#import "ConciseKit.h"

$ class

Method Swizzling

    [$ swizzleMethod:@selector(foo) with:@selector(bar) in:[Foo class]]
    [$ swizzleMethod:@selector(foo) in:[Foo class] with:@selector(bar) in:[Bar class]]

    [$ swizzleClassMethod:@selector(foo) with:@selector(bar) in:[Foo class]]
    [$ swizzleClassMethod:@selector(foo) in:[Foo class] with:@selector(bar) in:[Bar class]]

Path

    [$ homePath]     => path to user's home directory
    [$ desktopPath]  => path to user's desktop directory
    [$ documentPath] => path to user's document directory
    [$ appPath]      => path to app directory
    [$ resourcePath] => path to app's resources directory

waitUntil

Useful when writing tests for asynchronous tasks. Default timeout is 10 seconds, checking is done every 0.1 seconds.

    [$ waitUntil:^{ return (BOOL)(someConditionIsMet == YES) }]
    [$ waitUntil:^{ return (BOOL)(someConditionIsMet == YES) } timeOut:10.0]
    [$ waitUntil:^{ return (BOOL)(someConditionIsMet == YES) } timeOut:10.0 interval:0.1]

Singleton

Creating Singletons

    @interface Foo
    - (id)initSingleton; // <= add these to the interface
    + (Foo *)sharedFoo;  // <= where Foo is the class name
    @end

    @implementation Foo
    $singleton(Foo);     // => makes Foo a singleton class

    - (id)initSingleton {
      foo = 1;           // do initialization in -initSingleton method
      bar = 2;
      return self;
    }
    @end

Using Singletons

    $shared(Foo)         // => returns the shared instance
    /* or */
    [Foo sharedFoo]

Macros

General shorthands

    $new(Foo)       => [[[Foo alloc] init] autorelease]
    $eql(foo, bar)  => [foo isEqual:bar]
    $safe(obj)      => (obj == [NSNull null] ? nil : obj)

NSArray shorthands

    $arr(foo, bar)          =>  [NSArray arrayWithObjects:foo, bar, nil]
    $marr(foo, bar)         =>  [NSMutableArray ...]
    $marrnew or $marr(nil)  =>  [NSMutableArray array]

NSSet shorthands

    $set(foo, bar)          =>  [NSSet setWithObjects:foo, bar, nil]
    $mset(foo, bar)         =>  [NSMutableSet ...]
    $msetnew or $mset(nil)  =>  [NSMutableSet set]

NSDictionary shorthands

    $dict(v1, k1, v2, k2)     =>  [NSDictionary dictionaryWithObjectsAndKeys:v1, k1, v2, k2, nil]
    $mdict(v1, k1, v2, k2)    =>  [NSMutableDictionary ...]
    $mdictnew or $mdict(nil)  =>  [NSMutableDictionary dictionary]

NSString shorthands

    $str(@"foo: %@", bar)   => [NSString stringWithFormat:@"foo: %@", bar]
    $mstr(@"foo: %@", bar)  => [NSMutableString ...]
    $mstrnew or $mstr(nil)  => [NSMutableString string]

NSNumber shorthands

    $bool(YES)    => [NSNumber numberWithBool:YES]
    $int(123)     => [NSNumber numberWithInt:123]
    $float(123.4) => [NSNumber numberWithFloat:123.4]

    $char(), $double(), $integer(), $long(), $longlong(), $short(),
    $uchar(), $uint(), $uinteger(), $ulong(), $ulonglong(), $ushort()

NSValue shorthands

    $nonretained(), $pointer(), $point(), $range(), $rect(), $size()

Additions

NSArray

    [array $first] => [array objectAtIndex:0]
    [array $last]  => [array lastObject]
    [array $at:1]  => [array objectAtIndex:1]

    [array $each:^(id obj) {
      NSLog(@"%@", obj);
    }]

    [array $eachWithIndex:^(id obj, NSUInteger i) {
      NSLog(@"%d %@", i, obj);
    }]

    [array $eachWithStop:^(id obj, BOOL *stop) {
      NSLog(@"%@", obj);
      if($eql(obj, @"foo")) {
        *stop = YES;
      }
    }]

    [array $eachWithIndexAndStop:^(id obj, NSUInteger i, BOOL *stop) {
      NSLog(@"%d %@", i, obj);
      if(i == 1) {
        *stop = YES;
      }
    }]

    [array $map:^(id obj) {
      return $integer([obj integerValue] * 2);
    }]

    [array $mapWithIndex:^(id obj, NSUInteger i) {
      return $integer([obj integerValue] * 2 + i);
    }]

    [array $reduce:^(id obj) {
      return $integer([obj integerValue] * 2);
    }]

    [array $reduce:^(NSNumber *memo, NSNumber *obj) {
      return $integer([memo integerValue] + [obj integerValue]);
    }]

    [array $reduceStartingAt:$integer(1) with:^(NSNumber *memo, NSNumber *obj) {
      return $integer([memo integerValue] * [obj integerValue]);
    }]

    [array $select:^BOOL(NSNumber *obj) {
      return ([obj integerValue] % 2) == 0;
    }]

    [array $detect:^BOOL(NSNumber *obj) {
      return ([obj integerValue] % 2) == 1;
    }]

    [array $join]      => [self componentsJoinedByString:@""]
    [array $join:@","] => [self componentsJoinedByString:@","]

NSMutableArray

    [array $push:foo]    => [array addObject:foo]              (+ returns self)
    [array $pop]         => [array removeLastObject]           (+ returns lastObject)
    [array $unshift:foo] => [array insertObject:foo atIndex:0] (+ returns self)
    [array $shift]       => [array removeObjectAtIndex:0]      (+ returns first object)

NSDictionary

    [dict $for:@"foo"] => [dict objectForKey:@"foo"]
    [dict $keys]       => [dict allKeys]
    [dict $values]     => [dict allValues]

    [dict $each:^(id key, id value) {
        NSLog(@"%@ => %@", key, value);
    }

    [dict $eachWithStop:^(id key, id value, BOOL *stop) {
        NSLog(@"%@ => %@", key, value);
        if($eql(key, @"foo")) {
            *stop = YES;
        }
    }]

    [dict $eachKey:^(id key) {
        NSLog(@"%@", key);
    }]

    [dict $eachValue:^(id value) {
        NSLog(@"%@", value);
    }]

NSMutableDictionary

    [dict $obj:@"bar" for:@"foo"] => [dict setObject:@"bar" forKey:@"foo"] (+ returns self)

NSString

    [string $append:@"foo"]  => [string stringByAppendString:@"foo"]
    [string $prepend:@"foo"] => [NSString stringWithFormat:@"%@%@", @"foo", string]
    [string $split:@","]     => [string componentsSeparatedByString:@","]
    [string $split]          => [string componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]

NSMutableString

    [string $append_:@"foo"]     => [string appendString:@"foo"]           (+ returns self)
    [string $prepend_:@"foo"]    => [string insertString:@"foo" atIndex:0] (+ returns self)
    [string $insert:@"foo" at:1] => [string insertString:@"foo" atIndex:1] (+ returns self)
    [string $set:@"foo"]         => [string setString:@"foo"]              (+ returns self)

Contributors

License

Copyright (c) 2010-2012 Peter Jihoon Kim and contributors. This code is licensed under the MIT License.

More Repositories

1

goop

A simple dependency manager for Go (golang), inspired by Bundler.
Go
780
star
2

metamask-mobile

Port of MetaMask Ethereum Ðapp browser for mobile devices (iOS only for now)
JavaScript
134
star
3

factory-lady

a factory library for node.js / javascript inspired by factory_girl
JavaScript
119
star
4

wallet.ts

Utilities for cryptocurrency wallets, written in TypeScript
TypeScript
105
star
5

cipher-ethereum

A typed and fully-tested Ethereum library used by Cipher Browser, a mobile Ethereum wallet and Dapp browser
TypeScript
82
star
6

autoparts

package manager for nitrous.io
Ruby
81
star
7

socks

An easy-to-use web GUI toolkit for JavaScript, inspired by Shoes
65
star
8

ot.go

Operational Transformation backend written in Go compatible with ot.js
Go
36
star
9

underscore.objc

work in progress...
Objective-C
27
star
10

nitrogen-dist

Nitrogen: Atom, meet Cloud.
CSS
13
star
11

hterm

ChromiumOS hterm
JavaScript
9
star
12

ResetColorProfileAfterWake

Fix macOS bug that causes display color to get messed up after waking device from sleep
Objective-C
7
star
13

rubb

BBCode Parser for Ruby that supports nested BBCode tags.
Ruby
5
star
14

railscasts_xcode_color_theme

Railscasts Xcode color theme
5
star
15

dart-ethereum_address

A dart library to generate and validate Ethereum addresses
Dart
4
star
16

dotfiles

Vim Script
4
star
17

pubstorm-server

PubStorm API server
Go
3
star
18

usdc-l2-demo

USDC L2 Demo
TypeScript
3
star
19

tinymongo

Simple MongoDB wrapper
Ruby
2
star
20

ens-dnsname

Encode and decode DNS names for ENS using Golang
Go
2
star
21

skeleton

skeleton rails app for pairing interviews
Ruby
2
star
22

pubstorm-cli-go

PubStorm command line client
Go
1
star
23

go.vim

vim.go Vim plugins for Go (http://golang.org) - Extracted from Go official tarball.
1
star
24

rise-nginx

Lua
1
star
25

useful-ios-tidbits

a collection of useful ios code tidbits
Objective-C
1
star
26

fiat-token-gas-relay

TypeScript
1
star
27

petejkim.github.com

JavaScript
1
star
28

vim-colors-solarized-24bit-terminal

Vim Script
1
star
29

empty

1
star