MacRuby in Action
Brendan G. Lim with Jerry Cheung and Jeremy McAnally
Copyright
For online information and ordering of this and other Manning books, please visit www.manning.com. The publisher offers discounts on this book when ordered in quantity. For more information, please contact
Special Sales DepartmentManning Publications Co.20 Baldwin RoadPO Box 261Shelter Island, NY 11964Email:
orders@manning.com2012 by Manning Publications Co. All rights reserved.
No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps.
Recognizing the importance of preserving what has been written, it is Mannings policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end. Recognizing also our responsibility to conserve the resources of our planet, Manning books are printed on paper that is at least 15 percent recycled and processed without elemental chlorine.
| Manning Publications Co.20 Baldwin RoadPO Box 261Shelter Island, NY 11964 | Development editor: Sara OnstineTechnical proofreader: Nick HowardCopyeditors: Lianna Wlasiuk, Tiffany TaylorProofreader: Melody DolabTypesetter: Marija TudorCover designer: Marija Tudor |
Printed in the United States of America
1 2 3 4 5 6 7 8 9 10 MAL 18 17 16 15 14 13 12
Brief Table of Contents
Table of Contents
Preface
When I was first learning Ruby, I immediately fell in love with the language. I knew early on that I wanted to work with Ruby professionally, which became possible later when I created my first startup using Ruby on Rails.
I later worked for a Ruby on Rails consulting company where I spent a few years focusing on Ruby before I headed up the mobile development department. Ive had an interest in mobile development since I was young and it was a very exciting time to work on iOS and Android applications. With iOS development came the need to learn Objective-C, which ultimately led me into the world of Cocoa for Mac development.
I developed a few Mac applications personally and professionally and thought how great it would be if I could write Mac applications using Ruby. Id heard of RubyCocoa, but I knew of its shortcomings. Then I learned about MacRuby: it was the solution Id been waiting for.
When I was contacted by Manning to work on this book, I knew Id be able to reach many other individuals who were Rubyists and who wanted to create rich Mac applications without having to use Objective-C. This book is meant for you if you love the Ruby language and want to get into Mac development
BRENDAN G. LIM
Acknowledgments
Putting together a book like this is no easy feat, and many people behind the scenes worked countless hours to get the book into your hands. First and foremost, everyone at Manning deserves all the thanks we can give them. Without them, we wouldnt have been able to create such a great book for you.
We interacted frequently with a few individuals from Manning and would like to specifically mention them. Wed like to thank Troy Mott, our acquisitions editor, who originally came to us to work on this book and helped us through thick and thin. Sara Onstine, our development editor, guided us through the formalities of writing a book like this. And Marjan Bace, our publisher, always challenged us to find ways to improve the books content and organization.
Wed also like to thank our books production team. Lianna Wlasiuk, Tiffany Taylor, and Melody Dolab, our copyeditors and proofreader, read the entire manuscript and made sure everything was organized and presented properly. Nick Howard, our technical proofreader, caught errors that we didnt know were there.
Over the course of the development of the book, many people generously volunteered to review it to help make it as good as it could be. These reviewers deserve a tremendous amount of credit for the impact they made through their feedback. Our thanks to Pradeep Elankumaran, Brent Collier, Adam Bair, Philip Hallstrom, Mike Stok, Alex Vollmer, Coby Randquist, Jerry Cheung, Greg Vaughn, Warner Onstine, and Daniel Bretoi.
BRENDAN would like to thank his father, Chhorn, his mother, Brenda, and his two brothers, Chhorn and Chhun, for their support and encouragement. He also wants to thank his wife, Edelweiss, for her love and support and for letting him spend night and day working on this book. Last but not least, thanks to Pradeep Elankumaran, who let Brendan spend so much time writing this book after they both quit their jobs to focus on their startup, Kicksend.
JERRY would like to thank his parents, Margaret and Kevin, and his wise-guy brother Randall. Hed also like to remind Wendy that he beat her to her thesis (thanks, love, for letting me win this one). A special shout-out goes to Brendan for getting Jerry interested in MacRuby and Mac development in the first place.
JEREMY would like to thank his wife, friends, and dogs for sustaining him through yet another writing project. Without their support, he would likely end up a raving maniac under an overpass tapping out code examples while throwing cans at passing cars.
About this Book
MacRuby in Action was written to give Rubyists the ability to create rich Cocoa applications for the Mac OS X platform without having to learn Objective-C. Our goal is to have you, the reader, creating amazing Cocoa applications using MacRuby by the end of the book. Throughout the book, youll learn in the ins and outs of MacRuby while exploring the Cocoa framework, design patterns, system scripting, testing, and getting your application into the Mac App Store. We know that sometimes the best way to learn is to get your feet wet. Thats why youll be creating useful Mac applications along the way so you can apply the key topics as you learn them.
Who should read this book
This book is aimed at developers interested in writing software for the Mac platform. It doesnt matter if youre new to both the Mac and the Ruby language or youre an experienced Ruby developer looking to learn how to write Mac apps. If you have the desire to create beautiful Cocoa applications for the Mac platform and want to do so using the elegant and highly productive Ruby language, then this book is for you. If youre new to Ruby, we give you a brief overview of the language so youll feel comfortable enough to take on the rest of the book.
MacRuby in Action is also a more approachable introduction to Cocoa development than traditional Objective-C books. Throughout the book, we explore practical code examples that youll face when creating your own applications. MacRuby in Action can act as a guide for using MacRuby and Cocoa from the ground up, or you can use it as a reference if youre looking to dive deeper into MacRuby.
Roadmap
The book has 11 chapters divided into three parts as follows:
explores the inner workings of MacRuby and how to set up your development environment. Theres also an introduction to Ruby and an overview of Objective-C syntax. We then go into the MacRuby syntax, give a few examples, and end with two Hello World examples.