sugarcube v0.8

Now with communist leanings!

My employer, Fusionbox, has agreed to hand the development of SugarCube over to the community. Yay! This was at my behest, because right now I’m the only iOS dev there, and I’m breaking off to start my own independent contracting startup (wish me luck!).

New to sugarcube?

Check out my project page!

Yeah yeah yeah, new features!

The last announcement was v0.6. Most of the changes since then have been the usual additions (like more Symbol <=> UIConstant aliases, more factories), but there are some notable additions. Also, the UIAlertView.alert method has been fixed, for those of you getting that Objective-C stub for message... error.

Array, NSIndexPath, NSIndexSet

You can convert from NSIndexPath and Array very easily now.

ruby [0, 1].nsindexpath index_path.to_a

And you can use a case statement with indexpaths in a neat way by using the IndexPath class.

ruby def tableView(table_view, cellForRowAtIndexPath:index_path) case index_path when IndexPath[0, 0] # index_path.section == 0, index_path.row == 0 when IndexPath[MainSection, 1..5] # index_path.section == MainSection, index_path.row in 1..5 when IndexPath[true, 5] # any section, index_path.row == 5 end end

URL additions to NSString

Escaping a URL using the Foundation methods is really awful looking. What, you wanna see it? Fine!!

“`ruby

the UIKit/Foundation way. BLECH.

search_escaped CFURLCreateStringByAddingPercentEscapes( nil, search, nil, ”!*‘();:@&=+$,/?%#[]“, CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding) )

the sugarcube way. YUM.

url = "http://google.com/?q=#{search.escape_url}”.nsurl “`

Timer methods += after (aka later) and every

These are added to the Numeric class, and if you include SugarCube::Timer you can use them as global methods:

”`ruby 1.minute.later do puts “time’s up!” end

1.second.every do # second just returns self, but it is more readable to have it. puts “tick” end

include SugarCube::Timer every 1.second do puts “tick” end

after 1.minute do puts “time’s up!” end “`

UIPickerView

ruby picker[0] # => picker.selectedRowInComponent(0) picker[0] = 5 # => picker.selectRow(5, inComponent:0, animated:true)

UISegmentedControl

ruby UISegmentedControl.plain(["item 1", "2", "and three"]) UISegmentedControl.bordered(["item 1", "2", "and three"]) UISegmentedControl.bezeled(["item 1", "2", "and three"]) UISegmentedControl.bar(["item 1", "2", "and three"])

UIView#first_responder

There is a private UIView#firstResponder method, but Apple won’t let you use it. :-/ So here’s a new one!

”`ruby

searches the view hierarchy for a view that returns

true for view.firstResponder?

myview.firstresponder

search “globally”, starting at the root window

UIView.first_responder “`

UUID

I swear I didn’t know that BubbleWrap has the exact same method. Oh well!

ruby include SugarCube::UUID puts uuid # => "0A3A76C6-9738-4458-969E-3B9DF174A3D9"

Not a very exciting release, dude.

Yup. Sorry! All the cool tricks (UIView#shake, SugarCube::Adjust::tree) are already done! :-)