 So how many people here are still trying to blame their hangovers on the altitude? Yeah, you keep it up honest Yeah, we had kind of an impromptu open bar last night at the poor house and we're probably gonna do something like it again tonight So I don't know follow Thunderbolt labs. We'll tweet from there Yeah, you'll find us So can you hear yes, how's that? Good I'm not gonna put the mic in my mouth. It's not gonna happen All right, can I get a show of hands who many how many people here were here for the previous presentation by Rich Kilmer? Okay, fantastic. I'm gonna try not to get feedback too. That's good that was a really great presentation and The way we set ours up is we want to go a little bit more advanced into the practical side of doing a Ruby motion app Specifically doing client server development because that's this stuff that really excites us is combining mobile apps with The cloud side and we got three Three parts to this the first one is introduction to Ruby motion The second one goes into the client server stuff and the third part the final part talks about more of the why you would or Maybe would not want to go through motion So and actually one other quick question How many people here sort of actively are sort of develop client-server APIs, you know your JSON back in pushing something to like back Yeah, that's good. So one of the nice things about that is like when you start thinking about client server applications Once you do that it doesn't really matter whether the front end is a backbone app or you know Pick the new JavaScript hotness serenade maybe right or an iOS app They can consume the same JSON payloads So it's a lot less work and it's kind of important for reuse and keeping things pretty separated. Yeah Okay, so let's get started. So first of all introductions. My name is Tamer Sala. This is Randall Thomas and together we are Thunderbolt lap Or is it ebony and ivory? ebony and ivory Fun little story. I actually wanted to name us that He actually did try to name that. I vetoed it as a PC thing. Yeah Because I figured over the phone nobody be able to tell the difference between ebony and ivory Oh, so that you laugh at all right Yeah and We're gonna have maybe some time at the end for questions But that's not really how we want to do it really things a lot more interactive because we get really bored just standing up here on stage So if you raise your hand, we'll stop last question and it's much more relevant So please don't be afraid to interrupt us. Yeah or shout like we might be like staring at the slides By the way, raise your hand if you sat in this presentation just to heckle us There you go rich there you go All right, so All right, so first of all just to set the stage here, you know Randall and I And Thunderbolt labs in general we all have a wide variety of skills All kinds of things that we're good at right One of the things that we're not an expert in to be honest, we're not iOS people right we're not objective See developers who are trying out Ruby motion. We are Ruby developers who? learned the The objective see semantics and learned Coco through Ruby motion right so That's kind of a caveat that there are some deeper things in objective See and Randall actually has a lot more experience with the deeper embedded stuff that I do but in general There is stuff that you know, we're not experts on that, but it's the same Approach that we think most people in the community are taking where people are coming to this because they don't Want to deal with objective see do a lot of you that anybody in the room actually have really deep objective see experience like most people yes No, so okay, okay, that raises his hand Mike Clark He's laughing because he actually taught me iOS I actually went to a Prague studio course You don't count. Yeah, and I still get to say that we don't know it Mike You're just saying that because you see my code. Yeah. All right So anyways what we're going to talk to you about today is Ruby motion specifically for client server Applications is what we're excited about So first of all, let's talk about how you get started with Ruby motion what it actually looks like when you're on the command line Is that font big enough for everybody to see? And not at all. Okay. Let's let's bump it up. How's that? Better or yeah, I'll go one more and I might have to bump it down for other slides. I think that's fine So as you saw in the demo on the last presentation Creating a Ruby motion app is actually really simple. You just use the motion command much like Rails And you say just create a sample app and it creates an app called sample and you've got your app delegate And you can see this is Ruby code We're gonna get a little bit more into what the differences are in a second And then you just use rake to to build and run the application in the simulator So here's a quick syntax breakdown of the the differences with Mac Ruby and Ruby and and it was touched on in the last one, but I think we need to really hit this home that What you're looking at here mat view pass in a mat view region did change animated animated is That's the entire method. That is the selector with the crazy like Sometimes you've got named arguments except for when it's the first one or whatever. That's all the method name, right? and I have to pop it down. Sorry guys. Is that good enough for everybody? Yeah squints, maybe it'll be alright So it's the same as defining this objective C method and he's absolutely right. There is no bridge You actually are defining that objective C method when you do that And it's not the same Which is a little bit confusing when you're first coming into it It's not the same as defining a method that takes a hash of options and passing in a 1-9 Hash symbol. It's not the same thing, which means If you define these two methods where the keyword on the second argument is slightly different It's completely different method definitions and if you call one or the other You're actually calling different method definitions. You're not calling a method called mat view and passing in different options So this is really important because if you aren't used to writing objective C You're going to be spending a lot of time trying to figure out why something didn't draw until you realize that you're looking at the wrong method So, you know watch out for that, especially as you get started writing Ruby motion applications, right? Okay, so I know what well once it's actually out So like you said, that's actually in Yeah, that's you can right now. Okay, cool So I have not used it and we'll go into that in a second But I guess it does recognize that syntax when you're defining methods the actually the only actual syntax difference with Ruby is In the method definition when you say def Whatever and you pass in the keyword inside the method definition is not legal Ruby It is legal Mac Ruby and that's what this is based on So I'm gonna go back point that out right here so This region did change animated That's the bit that if you tried to do that through a normal 193 Ruby app It would be like I don't even know what the fuck you're talking about, right? Do you guys have a beeper for me? You're gonna need that. Okay, so One of the cool things that came out recently in just in general with iOS development And well actually in general with Apple development iOS and OS X development is the concept of storyboards who here Has used nibs in developing OS X apps who here's he's storyboards Who is yours cursed nibs when they? And remember when they try to improve it by serializing it to XML because that really made things really readable So storyboards are actually a really cool concept. I'm gonna give a real quick rundown of how this works Basically you drag UI elements under this palette and you kind of draw out what you want things to be and then you save it and Unlike other systems like I think how visual basic works it generates code that would create that UI instead of doing that it actually instantiates objects into memory that That are those those view elements and when you save it it actually marshals them down Basically like a memory image of this is what your view is and when your application launches it loads that nib Tosses it into memory and sets up some connections between your instance variables your outlets and your Selectors, I think it's called. Yeah, and how many people here have forgotten which direction they need to drag their ID outlets to Oh, holy shit. Yes. Yeah That's so much it's it's pretty painful But storyboards actually make that a lot easier because it actually especially with the new storyboard editor It's much easier to hook things up and test it than it was in some of the old iOS simulators Right with these storyboards each one of these little boxes that you're seeing and I know they're kind of hard to see Let me see if I can bump it up. Oh, no, that just does the fun It's an image by my own computer. That's great each one of those boxes is an iPhone screen and You're connecting them together by dragging from the button of one to the next box and you can actually run that Yeah, it's like director for iOS So you can actually run that and it'll run through this entire thing you just click these by it does nothing right But it's great for rapid prototyping and showing like this is what I think the app's gonna do and you can sell it for 99 cents in the app store, right? It's pretty cool So storyboards are pretty cool and you can actually use them with Ruby motion You basically you end up creating a storyboard in your resources directory and use Xcode to do that You change your rakefile so that the UI main storyboard file is set to the name of that storyboard then You make sure that for each element in Your form or whatever you're gonna be using for each element you make sure that it has a unique tag So I have to click on this password box. I have to click on the What is that a shovel I have to click on the shovel and then I have to go over to the view and set a unique tag on there and the reason you have to do that for each one of your elements is because in Your UI view controller class now notice. This is just Ruby here. We're using Ruby motion You have to set up methods that will grab that Item out of your storyboard So you have because you're a UI view controller you have a method called view That basically points at your your your What do they call it pain in the storyboard? Yeah, it's painful So you can say view a tag one two or three and now you've got it, right? That's the hard way of doing it and that's how you had to do it for a while question question Okay, we're gonna get to that in a second. So You're right. You would probably want to put some constants in there You probably want to put some constants of the problem is you can't set those constants in Xcode Okay, so one thing we actually need to be very clear about is you are no longer in Ruby land This is actually a very nice illusion over a horrible horrible dream, right? So what you should think about this is like Like that scene in the wall, you know where you're being chased by hammers and like your teachers like like going over the cliff And everything's all horrible or Brazil, which is another horrible movie Which has these terrible terrible nightmare scenes, but at the end he's like flying like a bird and an angel It's cool. This is like the angel scene behind the scenes You still get these ugly little things that poke their head through and one of them is like, you know Having written a lot of C++ we have defined statements all over the place and macro So shit like this doesn't bother us because you know, we started writing code in the 80s and then the 80s We did this shit. It's cool, right? So yes, you should but you're not in Ruby land anymore. So do it their way It's much less painful and and there is now this gem which is actually really nice that I be yeah, I be Which helps out. It's such a hack the way it works though. It's really incredible But it's it's the only way that really works. Well, so anybody here who doesn't like hacks cover your ears So please elucidate how this works. So you include this gem and we're gonna show how to do that with using bundler in a second And then you in your UI view control you extend it with I be and then you've got access to these methods that like outlet basically and You can say this view controller has an outlet which kind of means an instance variable that can point to part of the view Named email text field or name text field or button. Those are my outlets, right? Oh Sorry, I didn't oh yeah down there at the bottom you run rake design What happens when you run rake design is really fun so I be looks at all the the classes that have extended I be and Generates fake header files as though they were objective C classes Then it creates Temporary Xcode project Tosses those header files into there launches Xcode against that project and I think it creates a storyboard You might the manually create a storyboard for that project and then you can drag from the storyboard into this fake header file So how many people think that that's great. Come on. It's genius. It's fantastic What if you change code in the header, of course that goes nowhere Spoiled by rails console Rake test it is worth it to be able to use the magic that is storyboard now rich showed some gems that are being Written and worked on in order to give you this kind of DSL for making and designing interfaces I've played around with some of them. I have not found any of them to be nearly as natural or Or easy to use as storyboards one of the benefits of storyboards For example is that I can hand it to my designer and say just make it look pretty right and they can do whatever they want to that as long As they don't screw up the Associations that are set up and we're all good Okay, so the next thing that's too far is bundler So we have a blog post you follow that URL to get that blog post We're gonna put these slides up where to tweet about them. So you don't have to write any notes down right now Or you just search Ruby motion bundler, and you'll probably find that blog post Including bundler and Ruby motion is really easy Basically, you just modify your rake file. So you do require bundler and then a bundler dot require and it's a loads all of the Loads all of the gems that you have in your gem file. That's in your your repository just like you would with a Rails application so now you can use gems like bubble wrap and things like that that are built for Ruby motion You can also install the gem Coco pods so in here we've got our gem file that has the cocoa pods gem set up and Then once we have the cocoa pods gem cocoa pods is like a bundler like rich winning this a little bit cocoa pods It's sort of like a Ruby gem system for iOS develop or for objective C development, right? So we kind of bootstrap from Ruby gems into cocoa pods into now We can define these pods here and here we've got a couple pods defined like rest kit and Cocoa 2d things like that When I looked at the specs rich said there's 600 pods when I looked at specs about three months ago I think is when I when I looked last there's about 450 pods. It's probably grown since then. Yeah That's why you put in counting. We were actually too lazy to really yeah very But cocoa pods are great because it used to be the case you have to download the code for objective C library and Dynamically link it into your app and Cocoa pods takes care of all that for you and dependency management and everything you expect from a package manager, right? Okay, so now let's look at a couple of iOS patterns and how they look when you're using Ruby and again I'm not focusing too much on the cocoa framework because we want to get more into the Into the client server stuff. So let's look real quick One of the things that you have to do differently if you're used to being a Ruby or especially a Rails developers you have to think about Mobile development very differently you have to think about memory, right? so one of the patterns that's built into Matview controller and also table view controller and a few others is that it will automatically try and reuse components for you In order to save memory and not constantly be allocating stuff So that's really hard to see so let me try and bump it up here In here what we've got is a mat view view for annotation, right? And we first try and dequeue a reusable annotation view with identifier. Oh my god I love cocoa so much And then if we get that view then we set the annotation and configure it however we want And that's for a little flag that shows up on a map, right? If we get one then that means we have one that's no longer visible on the map area We can reuse that so let's use that if we don't get one if that's nil Then that means we just have to instantiate a new one and we give it the when we instantiate it We tell it what the identifier is view identifier we're using and it just goes ahead and uses that So it keeps kind of this cue of recently seen Annotations when you're scrolling around the map and if you need to show a new annotation somewhere else on the map It was reuse that because it needs to pay attention to memory So one other thing to notice especially because we're all lazy is you have a tendency to cut and paste these dequeue Reused with blah blah blah blah identifiers make sure you change the reuse identifier. Yeah You'll get some really fun behavior if you don't change that reuse identifier. Yeah, good times Delegation is another pattern this very popular in in a Cocoa library Who here has who here knows that the delegation pattern as Cocoa uses it? Okay about 10% So basically what delegation the way that Cocoa uses delegation is If you have if you're using a Cocoa library Component that it doesn't have enough information to be able to do everything it needs to do you give it a designated Delegator that it constantly calls back to with predefined method signatures saying hey can I do this or hey this happened? What do you want me to do right? It's like 99% of the time that delegate is actually yourself as the controller So yeah, sometimes it isn't I mean I think the way that they normally describe it is don't call me I'll call you right and it's good object-oriented design and In general actually I learned a lot of about really good programming by reading this book Cocoa design patterns that came out recently very good book So anyways, you can see here that for the table controller. We've got two delegate methods that we've defined one is Table view number of rows in section it gives us the section and basically that's saying how many rows? Do you want me to display dude and the second one is table view sell for row at index path? And that says give me the view that should represent that very give me the cell that represents that view at that space Basically, tell me what to draw when I'm drawing this cell Inside that method by the way it also uses that same memory management Pattern that we saw earlier where it tries to reuse those cells whenever it can so as you're scrolling through a table view When they go off the screen, they'll try and reuse them as you need new ones But yeah, so that is the delegation pattern now delegation Delegation was also there at the time because objective C Didn't support lambdas. It didn't support Anonymous procedures right see so when you whenever you had even a single method that you needed to act as a callback Objective C forced or Cocoa forced you to define a delegate that was usually yourself And then whenever something fired it would call back to you now objective C supports blocks and Ruby motion makes use of that by mapping Ruby blocks directly to objective C blocks if I'm not mistaken So here's an example of using UI views and animation stuff you can say animate with duration and then animations you give it a block of lambda and In there you define what you want the animations to be and how you want them to work and then when it's completed It calls this other lambda that passes in a finished flag or whatever and then you can do you can move on at that point Much better than the delegation stuff that the times that you still want to favor delegation is when you've got 20 methods you don't want to be passing in 20 blocks into a method call So instead you pass in a delegator, which is usually yourself and then you define all those methods and it's you know It's a good pattern. So one of the things to note here is anybody how many people who have actually played around with X code objective C Like most so how many people I actually keep the objective C documentation open while they code Every hand should go up right because nine times out of ten if you're curious on how you do something You need to look up what the delegate is for that application right because the delegate is basically where you get to hook in Your behavioral code If you start doing things and start messing with base classes starting deriving from things you're probably doing something wrong It needs to go into a delegate Okay, so now let's get into the client server stuff The first thing I want to show you guys is a library called af networking af networking is a low-level HTTP library written by the guys over go walla and basically they looked at the the NS Was it NS URL connection? And they looked at it and they said this is not good enough There's a lot of things that it does wrong so af networking does a lot of things right for example It takes care of streaming you can do progress monitoring you can do authentication you can All of the operations are actually Implemented as NS operations so you can throw them into an NS operation queue. They all get run in the background I think be a gcd. Yeah gcd grand central dispatch and then you can pause and resume them and things like that I believe the caching built into it and you also get seen success and failures the built-in Cocoa networking stuff. I don't know when it gives you a failure, but it's not based upon the return code That comes from the from the server this actually does failures based on the return code from the server Which is the way it should be it's a really great net library And it's one of the reasons why the the cocoa pod system and the objective C Ecosystem is really cool because they they have to be more concerned with correctness and memory management and stuff like this And this takes care of a lot of stuff for you It's really easy to use af networking. Let me bump that up That's about good One of the nice things it does is it builds as much as possible on the existing cocoa stuff So first we create a URL, which is a normal NS URL URL with string HBS URL calm And then we create a request an NS URL quest. That's also still just regular cocoa And then we had this operation AF Json request operation Json request operation with request. Oh my god. I love you request Success lambda. Okay. Yeah, I get that and failure nil which because I don't care if it fails. Who cares? Another question. Yeah Yes, Matt's here actually There you are who wrote bubble wrap Bubble wrap is based on the original cocoa networking stuff if I'm not mistaken Which has all of the the problems that the the last slide Showed you see yes, the reason I'm showing you this is because this is actually what you want to use as far as I know Well, I mean the problem with with the iOS community is that you don't see into a lot of applications as much as you do inside The Rails community or the Ruby community. There's a lot more Transparency in the Ruby community But I'm willing to bet that very few people actually use the the straight cocoa networking stuff If networking is very popular great Yes, yes, AF networking is also built on top of the same same cocoa APIs that bubble wrap is using But AF networking adds The operation stuff right and it adds same response codes and things like that It also returns straight JSON. You can see that the Jays this is the last thing here is actually JSON It's it's already decoded for you There's something else I'm gonna say about that That's what I was gonna say. Thank you. Thank you So that brings up kind of a bigger thing that we're gonna touch on later as well But yes, there are a lot of really interesting Ruby libraries that really abstract away what the cocoa framework is But if you ever think that you might need to migrate away from Ruby motion God forbid or if you want to see more examples from the community of like, oh, how do I fix this issue? Relying upon the kind of the native libraries is a very good idea Yeah, so just so you know once again part of the problem is that this stuff looks like Ruby, but it isn't it's like and it's really funny I remember we were looking at some code samples Taren and I and I I got to the end And I didn't realize until I'm like you're missing a curly brace. He's like no, dude This is Ruby right you have to think you still have to think in an objective seat basically, right? So it's always better to be able to the other thing is if you look at the examples most of the examples that you'll want to translate into Ruby motion are actually written in like the Basically the OS 10 developer library the developer notes have a lot of really great examples And they're like really neat zip libraries So a lot of time you just download the code just to see how they do very small functions So in order to be able to translate it from objective C into Ruby motion You need to be able to sort of be comfortable with unfortunately as long and ugly as those those method calls are yeah To kind of figure out what the name of that method should be and how it actually translates over All right, and AF network is also built for subclassing which makes things really nice So you can actually define I call this my client they have example clients for Twitter and for app.net and stuff like that But basically once you define this class the subclass is from the AF networking client or AF client I think it's called then it's very easy to get a URL and just parse the JSON right out of there from anywhere inside your application Okay, so the second thing I want to talk about is SD web image It's caching asynchronous image downloader and this is just written by some dude And that's the URL right there Here's the when I first wrote a Ruby motion app that had to do a table view with some images in there This is the code that I used to populate the images from URLs in the table view from s3 Now this is we just said this is what you're not supposed to do who here knows why yeah But you can answer who here knows why is a bad idea raise your hands all right went back there Yes, so to repeat what he said the call is blocking and your world will just freeze and horrible things will happen people are dying I'm paraphrasing There's there's mobile apps for medical stuff So you down like that Synchronously God kills a kid and this is this is an important thing This is one of those things that it's like you're not used to this with Ruby with Ruby and rails. That's not true We have that thread class rumor That's right class and Ruby there if you're if you're if you've been writing Big rails apps, then you're like, okay. I need to worry about how many back-end hits. I'm doing I need to use promises I need to you know make them concurrent Maybe you return status of the clients or something if you're doing a lot of JavaScript work still less so you have to worry about blocking with With iOS application development and OS 10 application development you seriously have to worry about this stuff Any block is just you know a zero rating on on the app store, right? So so this is bad because like he said it'll block for each image sit there for two seconds Well, it loads it from s3 populates it goes on to the next one over and over again really great Basically you get the the giant beach ball of death, right and I don't know who this hippie is but I Think we're probably gonna hire him Okay, so this is SD web image And this is how you use it here and it's really easy All you do is you you include it via Coco pods and we already showed you how to do that and then again you just get a regular NS URL this cocoa Cocoa URL and then here you also do a placeholder a local image You're gonna use while it's loading it and then it adds a method set image with URL onto your image view And so you give it the URL you give it the placeholder and it just does it It's just like magic uses a background thread or maybe GCD and just loads it loads them all at the same time So it works really well very easy. It's like a no-brainer. So we've mentioned this a couple times It does everything with GCD is grand central dispatch. You've heard about it. Like it's not some mysterious thing I'm not seeing a lot of hands go up Okay, thank you Doing it. Oh, no, I think people okay for those who don't know what GCD is GCD was actually a way to do Dispatch and get callbacks by actually assigning blocks and see which was not a negative feature of C right so it's a very efficient way It's basically it's supported by OS 10 and iOS. It actually has operational cues that you can put Essentially a callback method in to be executed in System worries about scheduling. It's much easier than doing threats, right? So a lot of times you'll end up using GCD instead of doing a thread if you want to do like a regular running process or something like that So it basically greatly simplifies things that you would ordinarily have to do in a threaded or multi-threaded environment. Yeah Okay, so here's the big one This is the this is the mother-bomb of all like how you do client server stuff with iOS and it's called rest kit it's built on top of AF networking as of this new version and Basically, it's an HTTP JSON or M And it's written by the guys over a gate guru and it's a wildly popular library something you could really depend upon It's also now a moving target fun fun fun So within about two months rest kit zero point two zero is going to drop and as you would expect from a point release it changes everything so This this presentation is focused on the new API of rescue zero point two two zero Which is like I said, I think it's gonna probably drop in about two months It's hard to say there's a development branch going on that is almost a hundred percent different. It's good times But rescue is really nice It's very easy to use and it's a very clean division from an object or a point of view point of view And it's really good. Basically you write a polo I knew you're gonna Got got what God? You write a plain old Ruby object or Jesse did a presentation on maglev and just Anybody calls it polo. So go fuck yourself Jesse And then you tell rest kit what Json the map and how and then you get a you RL and like magic rest kit goes through all the way back and returns to you your plain old Ruby objects Which is really nice unlike active record. You don't have to write your your classes You have to write your models such that they know about active record Jesse you better plug your ears for the next three slides There's no system in Ruby that can persist classes like this when they don't know about Okay moving on So you write a polo and Here we got just class person with the two attributes everybody everybody's Rubius everybody knows what that is, right? And here's the Json that we're gonna get back from the server This is by the way anybody you may come on read the data I didn't think anybody would get that I'm touched classic of sitcoms. Yeah creepy so this is the Json that is actually can somebody help me out. Is this the standard Json that's returned from rails when you get slash people Yes, this is not the active model serializer Json I Use any by the way who here is use Jose Villam's active model serializer Seriously, holy crap. It is so good. It's perfect for Json Servers it's beautiful and it makes everything clean and nice Anyways, so this is the Json We're gonna get back from the server and we already know this ahead of time We don't need to control that and now we just tell Json what Js or tell res kit with Json to map It used to be easier. It's like half the lines of code, but with the new version of res kit This is what you have to do So it's a lot of fun This is your app delegate. This is the main god class for your entire application It's called the app delegate because it is set as the delegate for your application So whenever whenever your application needs to ask a question it asks your app delegate It's also usually the junk drawer for oh my god. I just need something global, right? So the other thing is how many people are starting to see exactly how see like Ruby development can be Yeah, it it looks like I'm developing cocoa, right? Sorry Objective C So what I have here is in and this is actually this is not the cleanest way of doing it You should be pulling it out into another server class, but I'm just doing it here to make it easy to illustrate In your application did finish launching you were with options Get a URL for the back end set it to an accessor called back end that we have set there and then you add a couple of mappings You have this person mapping which over here. You've got this hash It says for the class person map it with this dictionary ID maps to remote ID and name maps to name right and then I add that mapping for all successful response codes and With a pass in the mapping there and then I add that descriptor to the back end It's complicated, but it's much more flexible than it used to be so it's actually it is actually a win believe it or not So up here you can see me calling it so basically I'm saying if I ever receive anything that's that's got the key person Then assume that whatever's after that is going to be for the person class and map it using the ID to remote ID Named a name mapping that I passed in same thing if I ever receive something plural people assume that it's Part of that class and map it in the same way Res kit takes care of the fact that one is a singular and one is a an array Res kit will just take care of that. I'll figure it out. It'll assume assumes that they're all people right Then I just get an arbitrary URL That's the wrong direction So here we're in some other view and when it appears we go ahead and initiate a network request Here I'm using app.delegate. That's actually a bubble wrap feature One of the nice ones there and I'm asking the back end to get objects at path slash people And I'm not passing any extra params although I could it just be a hash And I get a success lambda and a failure failure lambda and once once those callbacks trigger then I can modify my view to to have all the rest of stuff there and It returns your models like magic. So inside that success lambda you have operation and result I don't even know what you're supposed to do with operation, but the result If you call it the operation is the operations queue I think it is the operation queue. So then maybe I could re queue it So, you know, I want to do it again or something like that. I don't know But the result that array returns the array of person objects If I know that I'm getting what should be a collection that I'm going to call result that array If I know that I'm getting what should be a single Instance then I call result dot first object and it just returns me the first one if there's any in there and That's that's the basics of rest kit You can also that's that's for just reading you can also go into full crud and here That's not good. Okay. I'll speed up a little bit For full crud we have to so first we told it how to map stuff when I did when I get a response Now is it tell it how to map back if I'm doing a request, right? So we say add request mapping, which is a method down here that uses that same person mapping this is the same method we had before and reverses it saying well just map it backwards, right and Tells it what what the key should be which is person and that's it and from that point on we can also do And then also sorry Because now you're doing the full crud you could just have your app embed all these arbitrary URLs throughout the application That gets really messy. So rest kit includes a routing system as well So I could set up a get route a put route a delete route and a post route for For the person class and I tell it what the pattern is for that URL And it'll it'll ask the person for remote ID to fill out that URL when it needs to and I just add them All to the router and then it's as simple as saying if I want to create a new person then I just say post object person and It'll post it with the correctly nested Attributes for a Rails application to consume Or I can update a person and again because this is the update method We told it that the path has remote ID. So it'll ask It'll ask the person what its remote ideas and figure it out. So it works really well Say again. Oh No, because you don't need to with rails rails only has underscore method in the forms because browsers themselves cannot understand put but once you hit rails as No, this is a put, but if you but this is via an API So once you if you do a put to rails, you don't need underscore methods. It's actually talking about the typo Or do I have a type of yeah, because we put post on the bottom. Oh, thanks jackass Yes, so sorry typo supposed to say put down there. Thank you We told you shout out questions. I was going to show a demo, but I'm really running out of time And I want to get into the more important rest kit can do The demo was really simple. Just a table view reading writing. It'll actually be available later It's rescue can do more I can do object relationships So people has have many tasks and you can you know do full credit on those it does core data It does some caching you can do image uploading and all kinds of stuff like that. It's a really powerful library The big question with it probably everybody really came to talk about is is Ruby motion worth it? So first let's talk about some of the bad aspects of Ruby motion So Rich kind of talked about this, but I honestly I kind of felt it was danced around a bit. You don't use Ruby gems Most of time you don't want to because they're huge and they're not designed for a vented callback like things They'll block and also and all sorts of things, but even if you did you can't so things like active support pluralizations and things like that you can't use that Because Ruby motion does not support the require statement because we motion you mentioned that maybe it will require support require Okay, but not but not to pull in third-party gems. Okay. Yep and And I say like again, it's not necessarily a bad thing But it does mean you end up having to re-implement some methods to get some conveniences that you might be used to And there's so there's no require. There's no about you probably wouldn't want that anyways This has gotten a lot better, but we have seen while we were developing Ruby motion apps some seriously interesting books So this one wrong number of arguments note negative. What is that 13 billion something for zero? So clearly I didn't pass enough arguments into that in that method It didn't give me a method name or a line number or a backtrace But you know it was fixed Lauren fixed it. I think that one was fixed within a week You know, but that kind of roadblock because it's a closed-source system I couldn't just dig it and figure out what's going on So that that is you know something you should be aware of that you might end up having blockers for a short short amount of time And it's moving fast. So When we gave a presentation similar to this there was more just the basics of a remotion over at Barcelona bar Rico Yeah, and at that time There were a lot of these bugs since then working on this I think I've encountered two One was actually rest kit and the other one Lauren fixed within a day So it is a fast-moving system and there was no debugger support at all originally Right pretty much you were on your own now the debugger support which showed some of it So we're looking at things they're adding features Still as of this very moment, there's a lack of what I would call strong debugging tools There is now gdb, which is good. Wait, how many people here have actually used gdb? How many have enjoyed in line? With no okay good. How many people enjoyed it? Yeah, of course you did Brian Brian So I mean it's much better than it used to be you can use gdb But you don't get even even the rudimentary Xcode debugging is way above and beyond what that gives you right? So now like rich said there is a company working on a GUI Debugging tool. Is that part of the Ruby mine? Okay, so Ruby mine is working on the the GUI debugging tool if you want to use and actually one other question Does that debugger include the symbol support because that was a big deal? Okay does include simple support. That's good Okay, I jumped through like three. Okay. The other one is that cocoa is huge when I first heard about Ruby motion I'm like great. I can write Ruby absolutely so simple and I could just you know call whatever like and use no kogiri and stuff No, no, no, you're still writing a cocoa app and that's the bulk of the pain Yeah, and I actually I basically laughed at him and went back to writing stuff in Xcode He likes to write it in C++. I wasn't in the other thing is it is closed source So that does mean that you know it is a Liability But it is an amazing team that's doing it. Go ahead. Right. So we I'm fairly certain that rich actually has a medical team following Lauren at all times Actually did I hear something about the code being an escrow rich? So what happens if if Ruby what happens if hip-bite goes under? Okay, I appreciate that because there are situations when you're when your larger company Licensing somebody else's code that you'll have it in escrow with the knowledge that if that company goes under if they get bought Something like that you get the code be really interesting to see if hip-bite could do something like that for open sourcing the code afterwards, right? Apple It is possible to tell that this is a Ruby motion application Apple You know, I can't imagine why they would but they do other things. I can't imagine either so like break maps It's just a small liability, right Yeah, yeah, absolutely. No, no, of course. No, no, no. Ios itself is a closed-source system even after Steve Jobs died He's not dead. Okay, but here's the good parts the glory You get the expressiveness of Ruby and it is expressive. This is An example of a couple of lines of objective C. Oh my god. Do I hate the syntax of objective C? I actually like the cocoa framework because I think it's a well laid out of Object-oriented framework for development is consistent. It's nice objective C is so ugly and painful So that one header files. Yeah about once a day. I just see tamer pull off his headphones start screaming and cursing Fuck fuck. I'm like, what's going on? Did something die? What happened? He's like this makes no sense and I'll look at his screen and I'll have some he's trying to type of Ruby method but it's objective C method like you know, we'll call application with delegate and animation plus your mom and He's basically seeing their cursing at him like dude. It's just it's this is where you have to remember It's still objective C you're writing no matter how much you think you're writing in Ruby. It's still objective C Right and here's another example. This is that same table view thing with the with the reuse of cells I am not going to go through how this works because it hurts, right? But it's just it's so less expressive It's so hard to understand what's going on No more Xcode. This is my favorite as well this how many people have followed the the tumble of Text from text from Xcode. It's hilarious It's great This this happened to me on a daily basis and I Xcode crashes so hard that People are like well, you need to wipe your Xcode directory and reinstall Xcode tamer still believes that your dev tools shouldn't troll you Right I've used emacs, so I'm not quite sure if that's true and and so you can use whatever editor you want that slide and didn't you No, I mean frankly you're gonna code it in vim. You're gonna drive it with break. That's how a unix kid does shit I mean come on and It feels great to not have to launch Xcode the only time you have to launch Xcode is to do that storyboarding stuff And it's not very painful, but this is this feels good And you're using the same language as you use in the back end You're not going to reuse a lot of components because like we said, you know, you can't use gems You might be able to like cut and paste some stuff. That's about it But more importantly you've got the same skill set on the front in the back end And that's actually really important for building a product and building a team. It smooths things out, right? And you've got the ethos of the Ruby community very interesting that in Objective C You can actually basically do anything you can do in Ruby with the exception of the fact that Apple won't Allow you to avow stuff at runtime, right? But the Objective C community is just they're so against anything that's at all magic. They want everything Very wet just very laid out like repeat it over and over again because they don't get just boilerplate They don't care Ruby's not like that. And so it's interesting to me to see where some of these libraries are going to go in terms of Making things much easier. Yes in the back You're saying is that why would we be advocating this level of abstraction when you already have to do this? Well, no He's saying we've already said that we would not encourage this level of abstraction and now we're talking about how it's a benefit Oh, we'll see. Okay. Here's the difference what we're not encouraging is a level of not understanding what your extraction abstraction is and when it breaks So the perfect example of this is how many people remember the off by one errors like in active record originally where people would pull back all And then you'd see all dot first, you know, or all that and then they have an array index and they use the first one That's a breaking abstraction because people don't understand what they're doing when they do that is before scopes, of course, right? And before a roll. Yeah. And also importantly, I'm just conservative. So I think some of these abstractions will become good Maintainable abstractions, but it's always the case that the first ones are Abstractions that you cannot build upon and so we're going to avoid that stuff. That's how we are, but go ahead rich For the same reason that I just said because I'm conservative rest kit is a very mature library No for point two zero, but you could still use the previous version of rescue Yeah, it's totally stable And you're right though rescue it did make a big change and I wish they had bumped it to a major version when they did that They should have when they do some And you might need more Yes, that's a decent point that Can you summarize? Yeah, his summary is he It is possible to view Ruby motion as a prototyping tool and then maybe it will build with you but if you're doing that you should start with the simplest thing and He posits that his library is the simplest thing bubble wrap. We're speaking over here No, and so the other thing is to remember is that objective C has a much longer history in terms of its level of abstraction Then Ruby just bear with me on that. I know that's a little contentious Right, but the delegate patterns and the way they do use MBC is literally hard-coded in the cocoa APIs You have to remember objective C is the language in which you write a cocoa application Right, you can write one in C++, right? You just flip the switch and you can actually do it in C++ You know it will be upon your head if you do it, but you could So the thing to remember is that you actually have to learn cocoa and you have to understand what cocoa expects your abstractions to be And if you fight against it, you're just gonna have a world of hurt So which is one of the reasons why for instance you go you basically use the abstraction that cocoa provides much more often than use The abstractions that Ruby or even something like Rails would provide all right, so Right, so the question is production versus demo or internal tool now when we gave us talk three months ago I said I think this will be production ready like Thunderbolt labs a very conservative development shop would use this for a client application In maybe six months and that's how things are progressing. That was about three months ago Right and at this point, it's actually progressed faster I'm still not sure if we would use this for a client application where we had to hand it off to client developers at this point But it's certainly getting closer so Right So we also we're writing a book on ebook on doing Ruby motion with rest kits. It's gonna be done in about two weeks to a month if you want to see example code and More in-depth the details of how to do some of the more advanced stuff with rest kit there's follow Thunderbolt labs on Twitter and we'll announce it there and That's it. I don't think we have any time for questions a little over but actually maybe take one Yeah, okay, nobody's gonna stop me go ahead Quietly Yeah, do no objects respond quietly with review motion no it will raise us if you try and call a method on a no object you'll get The normal Ruby exception on that so it tries to stick to Ruby as much as possible Just so you know the pattern and objective C is because you can dynamically attach methods using selectors an objective C If you call on a nil selector, it's not considered an error, right? Exactly, yes. Yeah, if you use Mac Ruby on your laptop, that's the same It's the same Ruby semantics as Ruby motion any other questions Sounds like that's it. So thanks. Thank you very much