Giter Club home page Giter Club logo

chuzzlekit's Introduction

ChuzzleKit Build Status

A chuzzled object is nil if it is falsy, otherwise it has its falsy parts removed.

For example:

  • @"".chuzzle is nil
  • Also @" ".chuzzle is nil
  • And @"\r\t".chuzzle is nil
  • @" 2 ".chuzzle is @"2"
  • @[].chuzzle is nil
  • @[@"", @1].chuzzle is @[@1]
  • [NSNull null].chuzzle is nil
  • @{}.chuzzle is nil
  • @{@1: @""}.chuzzle is nil
  • @{@1: @"", @2: @" 2 "}.chuzzle is @{@2: @"2"}

Note that: @" 2 3 " chuzzles to: @"2 3", that is, it only trims the string, it doesn’t eat the internal whitespace. This is because the “falsy” whitespace is just the trailing whitespace, not the internal whitespace. This is probably what you expected.

Mutable Chuzzling

We removed mutable chuzzling. There are issues with adding category methods to mutable variants in Cocoa, which led to us having to enact hacks. However there were unexpected issues, eg: #3

Custom Chuzzling

All our chuzzle methods on container classes will call chuzzle on the objects they contain, if it is implemented.

So if you want to support recursive chuzzling on your own objects, simply implement a chuzzle method.

Making JSON PLIST-Compliant

Since NSNull cannot be encoded into a PLIST, a convenient (but by no means the primary) usage of ChuzzleKit is to make saving JSON to a plist not crash (eg. via writeToFile:atomically).

Stripping Strings

-chuzzle can be a less enormous alternative to -stringByTrimmingCharactersInSet:, just don’t forget to expect nil in the response.

chuzzlekit's People

Contributors

hendriknoeller avatar kylef avatar mxcl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

chuzzlekit's Issues

@import Foundation.NSCharacterSet;

What is this line for?

@import Foundation.NSCharacterSet;

It doesn't compile on iOS project

Should it be replaced with:

#import <Foundation/NSCharacterSet.h>

Crash chuzzling an NSBigMutableString

We encountered a crash in ChuzzleKit (as used by PromiseKit) when URL encoding a string that came out of a text field. The issue here is that for performance reasons, UIKit hands out a pointer to the internal mutable string representation (which can be an NSBigMutableString for long strings) and we were handing that to PromiseKit.

To fix this in our app, we made an immutable copy of the string we get from the text field and use that to call PromiseKit.

However, it would be best if PromiseKit didn't cause a crash if someone does this.

The 'crash' is the following exception at line 16 of Chuzzle.m (the mutable string copy line [(id)self setString:s];):

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', 
reason: 'Attempt to mutate immutable object with replaceCharactersInRange:withString:'

You'd think an NSBigMutableString would be mutable based on its name, but apparently not in all cases (at least you can't always call setString: on it without this happening).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.