Because Objective-C should have inherited more from Smalltalk

Related tags

Utility OpinionatedC
Overview

OpinionatedC

Build Status Coverage Status Carthage compatible CocoaPods Version

Sometimes, Objective-C is just overly verbose. Life is too short to enumerateObjectsUsingBlock and who has the time to create sub-arrays with filteredArrayUsingPredicate anyway?

OpinionatedC is here to fix that. It offers a ton of Smalltalk-style convenience extension methods that make writing concise, easily readable Objective-C code a pleasure.

Usage

The easiest way to include OpinionatedC into your project is through CocoaPods:

pod 'OpinionatedC'

Import the umbrella header everywhere you want to taste the sweetness of OpinionatedC:

#import <OpinionatedC/OpinionatedC.h>

A Note About Method Prefixes

There is no doubt that the best practice for extension methods in categories is to include a vendor prefix in the selector. Currently, OpinionatedC does not conform to that best practice, since having to write (and read) stuff like oc_each: instead of a plain each: does not really seem to contribute to readability.

However, I'm currently looking for a method to allow optional, configurable method prefixes for users that want (or need) them. Feel free to add to the discussion in #1 if you have any ideas about this topic.

Features

The complete list of features is available on the official OpinionatedC website.

Here is a small potpourri of what is possible with OpinionatedC:

[@[@"hello", @"world!"] average:^NSNumber*(id each) { 
    return @([each length]);
}]
// => @5.5

NSSet *set = [NSSet setWithObjects:@"foo", @"bar", @"hello", @"world!", nil];
[set groupedBy:^id(id each) {
    return @([each length]);
}]
// => @{
//        @3 : a NSSet(@"foo", @"bar"),
//        @5 : a NSSet(@"hello"),
//        @6 : a NSSet(@"world!")
//    }

[@[@"foo", @"bar"] each:^(NSString *each) {
    NSLog(@"%@", each);
}]
// => foo
// => bar

[@"abc" eachWithIndex:^(NSString *each, NSUInteger idx) {
    NSLog(@"%@ - %@", each, @(idx));
}]
// => a - 0
// => b - 1
// => c - 2

[@[@"a", @"b", @"c"] isEmpty]
// => NO

[@[@1, @2, @3] map:^id(NSNumber *each) {
    return @([each integerValue] * 2);
}]
// => @[@2, @4, @6]

[@[@1, @2, @3] inject:@0 into:^id(NSNumber *running, NSNumber *each) {
    return @([running integerValue] + [each integerValue]);
}]
// => @6

[@[@1, @2, @3, @4] allSatisfy:^BOOL(NSNumber *each) {
    return [each integerValue] % 2 == 0;
}]
// => NO

[@"abcdef" first:3]
// => @"abc"

[@{ @1 : @"foo", @2 : @"bar"} detect:^BOOL(OCAssociation *each) {
    return [each.key isEqualToNumber:@2];
}]
// => an OCAssociation(@2, @"bar")

[@{ @1 : @"foo", @2 : @"bar"} select:^BOOL(OCAssociation *each) {
    return [each.key isEqualToNumber:@2];
}]
// => @{ @2 : @"bar" }

[@{ @1 : @"foo", @2 : @"bar"} reject:^BOOL(OCAssociation *each) {
    return [each.key isEqualToNumber:@2];
}]
// => @{ @1 : @"foo" }

[@100 atRandom]
// => 77

[@3 timesRepeat:^{ 
   NSLog(@"hooray!"); 
}]
// => hooray
// => hooray
// => hooray

[[@1 to:@10] select:^id(NSNumber *each) {
    return [each integerValue] % 2 == 0;
}]
// => @[@2, @4, @6, @8, @10]

Contributing

If you have any questions, remarks, ideas or suggestions for improvement, don't hesitate to open an issue. If you are about to create a pull request, there are only a few things to consider:

  • open an issue first if you are not sure if your idea will be appreciated
  • indent with tabs, not spaces
  • write unit tests, aim for 100% coverage

Contributors

License

The MIT License (MIT)

Copyright (c) 2015 Leo Schweizer

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 OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
You might also like...
Reflection for enumerations in Objective-C.

ReflectableEnum A macro and a set of functions introducing reflection for enumerations in Objective-C. Features: get a string value for an enumeration

A Cocoa library to extend the Objective-C programming language.

The Extended Objective-C library extends the dynamism of the Objective-C programming language to support additional patterns present in other programm

The Objective-C block utilities you always wish you had.

BlocksKit Blocks in C and Objective-C are downright magical. They make coding easier and potentially quicker, not to mention faster on the front end w

Proper YAML support for Objective-C. Based on recommended libyaml.

YAML.framework for Objective-C Based on C LibYAML library (http://pyyaml.org/wiki/LibYAML) by Kirill Simonov. YAML.framework provides support for YAML

Contacts wrapper for iOS 9 or upper with Objective-C

ContactsWrapper Contacts wrapper for iOS 9 or upper with Objective-C. For the information translated to Russian, take a look at this link. Requirement

A reverse engineering tool to restore stripped symbol table and dump Objective-C class or Swift types for machO file.

A reverse engineering tool to restore stripped symbol table and dump Objective-C class or Swift types for machO file.

A quick and "lean" way to swizzle methods for your Objective-C development needs.

Swizzlean A quick and "lean" way to swizzle methods for your Objective-C development needs. Adding Swizzlean to your project Cocoapods CocoaPods is th

Data Mapping library for Objective C

OCMapper is a data mapping library for Objective C that converts NSDictionary to NSObject

ESTabBarController is a highly customizable TabBarController component, which is inherited from UITabBarController.
ESTabBarController is a highly customizable TabBarController component, which is inherited from UITabBarController.

ESTabBarController is a highly customizable TabBarController component, which is inherited from UITabBarController. Why? In real-world developmen

This library is for adding animation to iOS tabbar items, which is inherited from UITabBarController.
This library is for adding animation to iOS tabbar items, which is inherited from UITabBarController.

This library is for adding animation to iOS tabbar items, which is inherited from UITabBarController. Installation Just add the Sources folder to your

A log should tell a story, not drown the reader in irrelevance.

StoryTeller A log should tell a story, not drown the reader in irrelevance Story Teller is an advanced logging framework that takes an entirely differ

Challenge... counting game for kids... should be entertaining, educational and fun... o_O
Challenge... counting game for kids... should be entertaining, educational and fun... o_O

MultiTainment Simple multiplication game for kids. Possible to choose how many questions they want to answer and how hard shoud it be. Simple funny in

A declarative, thread safe, and reentrant way to define code that should only execute at most once over the lifetime of an object.

SwiftRunOnce SwiftRunOnce allows a developer to mark a block of logic as "one-time" code – code that will execute at most once over the lifetime of an

Ios-exercise - In this exercise applicant should implement a new feature into an existing sample app

Cooking app In this exercise applicant should implement a new feature into an ex

JSPatch bridge Objective-C and Javascript using the Objective-C runtime. You can call any Objective-C class and method in JavaScript by just including a small engine. JSPatch is generally used to hotfix iOS App.

JSPatch 中文介绍 | 文档 | JSPatch平台 请大家不要自行接入 JSPatch,统一接入 JSPatch 平台,让热修复在一个安全和可控的环境下使用。原因详见 这里 JSPatch bridges Objective-C and JavaScript using the Object

Tools for making SwiftUI navigation simpler, more ergonomic and more precise.
Tools for making SwiftUI navigation simpler, more ergonomic and more precise.

SwiftUI Navigation Tools for making SwiftUI navigation simpler, more ergonomic and more precise. Motivation Tools Navigation overloads Navigation view

Color framework for Swift & Objective-C (Gradient colors, hexcode support, colors from images & more).
Color framework for Swift & Objective-C (Gradient colors, hexcode support, colors from images & more).

Swift 3 To use the Swift 3 version, add this to your Podfile (until 2.2 or higher is released): pod 'ChameleonFramework/Swift', :git = 'https://githu

Each step you take reveals a new horizon. You have taken the first step today.
Each step you take reveals a new horizon. You have taken the first step today.

The story Seeing the animations behind Paper, or the transitions behind Mail, being in a world of flat design and transitions, user interaction, app b

A debug log framework for use in Swift projects. Allows you to log details to the console (and optionally a file), just like you would have with NSLog() or print(), but with additional information, such as the date, function name, filename and line number.
Comments
  • find practical way to allow optional extension method prefixing

    find practical way to allow optional extension method prefixing

    Since the best practice for category methods clearly is to have a vendor prefix, it would be nice to allow optional prefixing for the OpinionatedC extensions. The mechanism should be easily configurable, and rock solid when activated.

    A first idea is implemented (very roughly) on branch spike-optionalprefixes.

    enhancement help wanted 
    opened by leoschweizer 6
A declarative, thread safe, and reentrant way to define code that should only execute at most once over the lifetime of an object.

SwiftRunOnce SwiftRunOnce allows a developer to mark a block of logic as "one-time" code – code that will execute at most once over the lifetime of an

Thumbtack 8 Aug 17, 2022
Software Dummy Display Adapter for Apple Silicon Macs to Have Custom HiDPI Resolutions.

BetterDummy Dummy Display for Apple Silicon Macs to achieve custom resolutions. About M1 macs tend to have issues with custom resolutions. Notoriously

Istvan T. 8k Jan 9, 2023
A handy collection of more than 500 native Swift extensions to boost your productivity.

SwifterSwift is a collection of over 500 native Swift extensions, with handy methods, syntactic sugar, and performance improvements for wide range of

SwifterSwift 12k Jan 7, 2023
A handy collection of Swift method and Tools to build project faster and more efficient.

SwifterKnife is a collection of Swift extension method and some tools that often use in develop project, with them you might build project faster and

李阳 4 Dec 29, 2022
Lightweight utilities for making OSLog more pleasant

UnifiedLoggingPlus Lightweight utilities for making OSLog more pleasant. Integration Swift Package Manager

Chime 10 Oct 26, 2022
Soulful docs for Swift & Objective-C

jazzy is a command-line utility that generates documentation for Swift or Objective-C About Both Swift and Objective-C projects are supported. Instead

Realm 7.2k Jan 1, 2023
Catch Objective-C exceptions in Swift

ExceptionCatcher Catch Objective-C exceptions in Swift There are many Cocoa APIs that can throw exceptions that cannot be caught in Swift (NSKeyedUnar

Sindre Sorhus 98 Nov 23, 2022
💡 A light Swift wrapper around Objective-C Runtime

A light wrapper around Objective-C Runtime. What exactly is lumos? lumos as mentioned is a light wrapper around objective-c runtime functions to allow

Suyash Shekhar 139 Dec 19, 2022
Swift-friendly API for a set of powerful Objective C runtime functions.

ObjectiveKit ObjectiveKit provides a Swift friendly API for a set of powerful Objective C runtime functions. Usage To use ObjectiveKit: Import Objecti

Roy Marmelstein 850 Oct 25, 2022
Swift Property Wrappers, but in Objective-C. And done horribly.

TOPropertyAccessor is an open source, Objective-C abstract class. Similar to Realm's Cocoa API, it uses the dynamic nature of the Objective-C runtime to access the properties of any of its subclasses, and routes calling them through overridable access points.

Tim Oliver 3 May 23, 2021