News for hackers. Stuff that matters.
Re:Show HN: NSString + Ruby by dennis_vartan on Thursday October 10, 2013 @06:44PM (#6530493)
Like! Much as I love ObjC, reducing verbosity via better syntax can go a long way to making code more readable.

For example, I ended up putting together some defines like this after building a bunch of UI programmatically.

  #define RGB(r, g, b)     [NSColor colorWithDeviceRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1]
  #define RGBA(r, g, b, a) [NSColor colorWithDeviceRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:(a)]
RGB(255, 104, 0) may be a bit too C-ish, but it sure beats the long form. Have similar GRAY(x) and GRAYA(x) defines for producing grayscale colors.

Definitely interested to see more projects along these lines.

Re:Show HN: NSString + Ruby by wrl on Thursday October 10, 2013 @07:23PM (#6530617)
I prefer:

    #define RGB(color)                        \
        (((color & 0xFF0000) >> 16) / 255.f), \
        (((color & 0x00FF00) >> 8) / 255.f),  \
        (((color & 0x0000FF)) / 255.f)
Pass in an HTML-style color hex triplet.
Re:Show HN: NSString + Ruby by cheesylard on Thursday October 10, 2013 @07:18PM (#6530602)

    #define RGB(r,g,b) RGBA(r,g,b,1)
Re:Show HN: NSString + Ruby by bennyg on Thursday October 10, 2013 @11:36PM (#6531297)
I wrote a utility class with idiomatic Obj-C color methods like the one you mentioned and more. I hate to plug it, but I'm fairly proud of it. It also generates color schemes when you throw a UIColor object at it, and includes 100 different UIColor generics like [UIColor seafoamColor].

https://github.com/bennyguitar/Colours-for-iOS

Re:Show HN: NSString + Ruby by reginaldjcooper on Friday October 11, 2013 @12:19AM (#6531389)
Why on Earth would you hate to plug this? I could definitely see someone using this and being thankful they don't have to do it themselves. Hell, I'd use it if I hadn't already done my own category.

Suggestions: you might want to allow for three-digit hex strings and eight/four digit hex strings with alpha, I found that convenient in mine. And in the documentation it would be way cool if you made the names of the colors self-referential.

Nits: I would have made all the system color methods like "systemThingColor", capitalized RGB and HSB, and made "RGBDictionary" return @{@"red": ...} (and made static NSStrings for the keys so nobody needs to go to the .m file to see what will happen). Obviously I am a pedant and I live right on the edge of the 80 character limit; of these I'd only suggest making static dictionary keys as an actually desirable change.

Nice work, you shouldn't be ashamed to share it at all.

Re:Show HN: NSString + Ruby by khangtoh on Friday October 11, 2013 @02:32AM (#6531711)
looks really nice, looking forward to using it!
Re:Show HN: NSString + Ruby by numo16 on Thursday October 10, 2013 @09:19PM (#6530987)
I use a few like this in some of my helper macros[0] that I usually pull into my iOS projects.

[0]: https://gist.github.com/numo16/3407652

Re:Show HN: NSString + Ruby by stefan_kendall on Thursday October 10, 2013 @07:49PM (#6530724)
I use the same thing to construct NSDecimalNumber instances. N(100.5) instead of [NSDecimalNumber decimalNumberFromString:@"100.5"]

SO handy.

Re:Show HN: NSString + Ruby by bennyg on Thursday October 10, 2013 @11:36PM (#6531300)
You can do this now @(100.5) for NSNumber literals.
Re:Show HN: NSString + Ruby by dennis_vartan on Friday October 11, 2013 @12:42AM (#6531436)
And even shorter, just @100.5 if what you have is a literal. The parentheses are needed if you're boxing a value, e.g.: @(price + 100.5)

In detail: http://clang.llvm.org/docs/ObjectiveCLiterals.html