Tài liệu MacRuby in Action pptx

270 949 0
Tài liệu MacRuby in Action pptx

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

MANNING Brendan G. Lim WITH Jerry Cheung AND Jeremy McAnally IN ACTION www.it-ebooks.info MacRuby in Action www.it-ebooks.info www.it-ebooks.info MacRuby in Action BRENDAN G. LIM WITH JERRY CHEUNG AND JEREMY MCANALLY MANNING SHELTER ISLAND www.it-ebooks.info 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 Department Manning Publications Co. 20 Baldwin Road PO Box 261 Shelter Island, NY 11964 Email: orders@manning.com ©2012 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 Manning’s 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. Development editor: Sara Onstine Manning Publications Co. Technical proofreader: Nick Howard 20 Baldwin Road Copyeditors: Lianna Wlasiuk, Tiffany Taylor PO Box 261 Proofreader: Melody Dolab Shelter Island, NY 11964 Typesetter: Marija Tudor Cover designer: Marija Tudor ISBN: 9781935182498 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 www.it-ebooks.info v brief contents PART 1 STARTING WITH MACRUBY 1 1 ■ Introducing MacRuby 3 2 ■ Using Macirb and the Apple development tools 37 3 ■ Going beyond the basics with Xcode Interface Builder 64 PART 2 TAKE IT FOR A SPIN 85 4 ■ Using the delegate pattern 87 5 ■ Notifications and implementing the observer pattern 104 6 ■ Using key-value coding and key-value observing 120 7 ■ Implementing persistence with Core Data 141 8 ■ Core Animation basics 168 PART 3 MACRUBY EXTRAS 187 9 ■ HotCocoa 189 10 ■ MacRuby testing 203 11 ■ MacRuby and the Mac App Store 216 www.it-ebooks.info www.it-ebooks.info vii contents preface xiii acknowledgments xiv about this book xvi about the authors xix about the cover illustration xx PART 1 STARTING WITH MACRUBY 1 1 Introducing MacRuby 3 1.1 Introducing MacRuby 4 The MacRuby difference 4 ■ Setting up your environment 5 Hello World, part 1 6 1.2 Cocoa: What you need to know 7 Important classes and concepts 8 ■ How Cocoa implements common design patterns 10 1.3 Objective-C and Ruby: what you need to know 11 A shared heritage 12 ■ Objective-C 101 13 Ruby 101 17 www.it-ebooks.info CONTENTS viii 1.4 Diving into MacRuby 21 Class structure 21 ■ Creating MacRuby classes 23 Syntax and method signatures 24 ■ Using Ruby and Objective-C methods 26 ■ Creating user interfaces 27 1.5 Hello World, part 2 28 Creating an Xcode project 29 ■ Creating the interface 30 Creating the controller 32 ■ Connecting the interface and controller 34 1.6 Summary 35 2 Using Macirb and the Apple development tools 37 2.1 Using external libraries with MacRuby 38 Loading frameworks 38 ■ Loading Objective-C libraries as bundles 39 ■ Loading Ruby gems 41 2.2 Exploring Macirb 42 Comparing the Ruby and MacRuby consoles 42 Working in the MacRuby console 43 ■ Macirb tips and tricks 43 2.3 Building a Pomodoro application in Xcode 47 Creating a new MacRuby project 47 ■ Constructing the interface 50 ■ Creating the controller 53 ■ Connecting the controller and the interface 56 ■ Running the application 58 Releasing the application 58 2.4 Summary 63 3 Going beyond the basics with Xcode Interface Builder 64 3.1 About Interface Builder 65 History of Interface Builder 65 ■ Getting around Interface Builder 65 3.2 Creating connections 69 Understanding outlets 69 ■ Understanding actions 71 3.3 Creating the Todo List application 73 Constructing the user interface 73 ■ Creating the model 79 ■ Creating the controller 79 ■ Connecting outlets and actions 82 ■ Running and packaging the application 83 3.4 Summary 84 www.it-ebooks.info CONTENTS ix PART 2 TAKE IT FOR A SPIN 85 4 Using the delegate pattern 87 4.1 What are delegates? 88 How do delegate methods work? 88 ■ Implementing the delegate pattern 89 4.2 Delegation as an extension technique 92 Delegation the Cocoa way 93 ■ Delegation using Forwardable 93 4.3 Using delegation in a custom MacRuby web browser 94 Creating the browser interface 94 ■ Setting up the controller 95 ■ Implementing delegate methods in the controller 98 ■ Connecting outlets and actions 100 Taking MacRuby Browser for a spin 102 4.4 Summary 103 5 Notifications and implementing the observer pattern 104 5.1 Notifying multiple objects 105 When to use notifications 105 ■ Managing notifications 106 5.2 Setting up notifications 107 Creating notifications 108 ■ Posting notifications to the notification center 108 5.3 Queuing notifications 109 Using posting styles 109 ■ Coalescing notifications 110 Queuing multiple notifications 112 ■ Removing notifications 113 5.4 Responding to notifications 114 Adding notification observers 114 ■ Removing notification observers 116 5.5 Building an iTunes-notification observer 116 Creating the script 116 ■ Running the script 118 5.6 Summary 118 6 Using key-value coding and key-value observing 120 6.1 Simplifying code with key-value coding 121 Accessing object properties with KVC 121 ■ Handling unknown keys 123 ■ Understanding key paths and collection operators 125 www.it-ebooks.info [...]... HotCocoa Getting started 9.2 189 190 Built -in mappings 191 Applications and menus 191 More advanced layouts 198 9.3 Building a speech application using HotCocoa Laying out the views 200 speak to you 201 9.4 10 Windows and controls ■ Summary ■ 193 200 Making your application 202 MacRuby testing 203 10.1 10.2 10.3 10.4 Testing MacRuby applications with MiniTest 203 Installing and configuring MiniTest 205... at www.manning.com/MacRubyinAction Software requirements An Intel-based Macintosh running OS X 10.6 or higher is required to develop MacRuby applications You also need to download MacRuby, but it’s freely available at http:/ /macruby. org The book offers full coverage of MacRuby and Xcode 4 Author Online Purchase of MacRuby in Action includes free access to a private web forum run by Manning Publications... can’t follow along? www.it-ebooks.info Introducing MacRuby 1.1.2 5 Setting up your environment Install the Xcode development environment first It’s best to install MacRuby after you have Xcode set up on your machine If you don’t install in this order, tools such as Interface Builder (which is now built into Xcode 4) won’t be able to recognize your MacRuby code INSTALLING XCODE Registered Apple Developers... you’ll be able to pick any sections in the rest of the book and learn about the areas that are most interesting or relevant to you www.it-ebooks.info www.it-ebooks.info Introducing MacRuby This chapter covers ■ Exploring and installing MacRuby ■ Important Cocoa concepts ■ Objective-C and Ruby fundamentals ■ MacRuby syntax and methods ■ Developing with the Xcode IDE MacRuby gives you the ability to write... Using KVO to implement observers 128 Adding and removing observers 128 Manually notifying observers of changes 129 Responding to observed objects 130 ■ ■ 6.3 Building out the Product Inventory application 131 Creating the user interface 131 Using KVC to retrieve product information 132 Adding features with KVC and KVO 137 ■ ■ 6.4 7 Summary 140 Implementing persistence with Core Data 141 7.1 Introducing... 154 157 Filtering and sorting with predicates and descriptors 157 Fetching objects from Core Data 158 7.5 Creating a Core Data version of the Todo List application Building the user interface 160 Creating the tasks controller 161 Connecting the interface to the controller 164 Running the application and inspecting the persistent store 166 ■ ■ 7.6 8 Summary 167 Core Animation basics 168 8.1 Introduction... you, the reader, creating amazing Cocoa applications using MacRuby by the end of the book Throughout the book, you’ll 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 That’s why you’ll be creating useful Mac applications... system 3 www.it-ebooks.info 4 1.1 CHAPTER 1 Introducing MacRuby Introducing MacRuby MacRuby is an Apple-sponsored development project Over the years, Apple has shown support for Ruby as a language, and, since 2002, Apple has included Ruby as part of the Mac OS X operating system Apple bundled a Ruby Scripting Bridge implementation called RubyCocoa with Mac OS X Leopard Prior to MacRuby, RubyCocoa was... and the Cocoa framework together In this section, you’ll learn how MacRuby is different from past attempts at combining Ruby and Objective-C and what makes it such a great language We’ll also jump right into getting MacRuby installed onto your system and introduce you to MacRuby s class structure Let’s set the stage for MacRuby 1.1.1 The MacRuby difference The goal of MacRuby is to provide an implementation... 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 you’ll 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 you’re looking to dive deeper into MacRuby xvi . MANNING Brendan G. Lim WITH Jerry Cheung AND Jeremy McAnally IN ACTION www.it-ebooks.info MacRuby in Action www.it-ebooks.info www.it-ebooks.info MacRuby. illustration xx PART 1 STARTING WITH MACRUBY 1 1 Introducing MacRuby 3 1.1 Introducing MacRuby 4 The MacRuby difference 4 ■ Setting up your environment 5 Hello

Ngày đăng: 17/02/2014, 15:20

Từ khóa liên quan

Mục lục

  • MacRuby-front

  • brief contents

  • contents

  • preface

  • acknowledgments

  • about this book

    • Who should read this book

    • Roadmap

    • Code conventions

    • Software requirements

    • Author Online

  • about the authors

  • about the cover illustration

  • Part 1 Starting with MacRuby

    • 1 Introducing MacRuby

      • 1.1 Introducing MacRuby

        • 1.1.1 The MacRuby difference

        • 1.1.2 Setting up your environment

        • 1.1.3 Hello World, part 1

      • 1.2 Cocoa: What you need to know

        • 1.2.1 Important classes and concepts

        • 1.2.2 How Cocoa implements common design patterns

      • 1.3 Objective-C and Ruby: what you need to know

        • 1.3.1 A shared heritage

        • 1.3.2 Objective-C 101

        • 1.3.3 Ruby 101

      • 1.4 Diving into MacRuby

        • 1.4.1 Class structure

        • 1.4.2 Creating MacRuby classes

        • 1.4.3 Syntax and method signatures

        • 1.4.4 Using Ruby and Objective-C methods

        • 1.4.5 Creating user interfaces

      • 1.5 Hello World, part 2

        • 1.5.1 Creating an Xcode project

        • 1.5.2 Creating the interface

        • 1.5.3 Creating the controller

        • 1.5.4 Connecting the interface and controller

      • 1.6 Summary

    • 2 Using Macirb and the Apple development tools

      • 2.1 Using external libraries with MacRuby

        • 2.1.1 Loading frameworks

        • 2.1.2 Loading Objective-C libraries as bundles

        • 2.1.3 Loading Ruby gems

      • 2.2 Exploring Macirb

        • 2.2.1 Comparing the Ruby and MacRuby consoles

        • 2.2.2 Working in the MacRuby console

        • 2.2.3 Macirb tips and tricks

      • 2.3 Building a Pomodoro application in Xcode

        • 2.3.1 Creating a new MacRuby project

        • 2.3.2 Constructing the interface

        • 2.3.3 Creating the controller

        • 2.3.4 Connecting the controller and the interface

        • 2.3.5 Running the application

        • 2.3.6 Releasing the application

      • 2.4 Summary

    • 3 Going beyond the basics with Xcode Interface Builder

      • 3.1 About Interface Builder

        • 3.1.1 History of Interface Builder

        • 3.1.2 Getting around Interface Builder

      • 3.2 Creating connections

        • 3.2.1 Understanding outlets

        • 3.2.2 Understanding actions

      • 3.3 Creating the Todo List application

        • 3.3.1 Constructing the user interface

        • 3.3.2 Creating the model

        • 3.3.3 Creating the controller

        • 3.3.4 Connecting outlets and actions

        • 3.3.5 Running and packaging the application

      • 3.4 Summary

  • Part 2 Take it for a spin

    • 4 Using the delegate pattern

      • 4.1 What are delegates?

        • 4.1.1 How do delegate methods work?

        • 4.1.2 Implementing the delegate pattern

      • 4.2 Delegation as an extension technique

        • 4.2.1 Delegation the Cocoa way

        • 4.2.2 Delegation using Forwardable

      • 4.3 Using delegation in a custom MacRuby web browser

        • 4.3.1 Creating the browser interface

        • 4.3.2 Setting up the controller

        • 4.3.3 Implementing delegate methods in the controller

        • 4.3.4 Connecting outlets and actions

        • 4.3.5 Taking MacRuby Browser for a spin

      • 4.4 Summary

    • 5 Notifications and implementing the observer pattern

      • 5.1 Notifying multiple objects

        • 5.1.1 When to use notifications

        • 5.1.2 Managing notifications

      • 5.2 Setting up notifications

        • 5.2.1 Creating notifications

        • 5.2.2 Posting notifications to the notification center

      • 5.3 Queuing notifications

        • 5.3.1 Using posting styles

        • 5.3.2 Coalescing notifications

        • 5.3.3 Queuing multiple notifications

        • 5.3.4 Removing notifications

      • 5.4 Responding to notifications

        • 5.4.1 Adding notification observers

        • 5.4.2 Removing notification observers

      • 5.5 Building an iTunes-notification observer

        • 5.5.1 Creating the script

        • 5.5.2 Running the script

      • 5.6 Summary

    • 6 Using key-value coding and key-value observing

      • 6.1 Simplifying code with key-value coding

        • 6.1.1 Accessing object properties with KVC

        • 6.1.2 Handling unknown keys

        • 6.1.3 Understanding key paths and collection operators

      • 6.2 Using KVO to implement observers

        • 6.2.1 Adding and removing observers

        • 6.2.2 Manually notifying observers of changes

        • 6.2.3 Responding to observed objects

      • 6.3 Building out the Product Inventory application

        • 6.3.1 Creating the user interface

        • 6.3.2 Using KVC to retrieve product information

        • 6.3.3 Adding features with KVC and KVO

      • 6.4 Summary

    • 7 Implementing persistence with Core Data

      • 7.1 Introducing Core Data

        • 7.1.1 Core Data concepts

        • 7.1.2 Differences between Core Data and traditional databases

        • 7.1.3 Creating a base Core Data project

      • 7.2 Understanding the persistent store and managed objects

        • 7.2.1 Anatomy of a persistent store

        • 7.2.2 Working with the managed object model

        • 7.2.3 Working with entity properties

        • 7.2.4 Defining a managed object class

      • 7.3 Working with managed objects

        • 7.3.1 Creating managed objects and updating properties

        • 7.3.2 Persisting changes to managed objects

      • 7.4 Retrieving objects from Core Data

        • 7.4.1 Filtering and sorting with predicates and descriptors

        • 7.4.2 Fetching objects from Core Data

      • 7.5 Creating a Core Data version of the Todo List application

        • 7.5.1 Building the user interface

        • 7.5.2 Creating the tasks controller

        • 7.5.3 Connecting the interface to the controller

        • 7.5.4 Running the application and inspecting the persistent store

      • 7.6 Summary

    • 8 Core Animation basics

      • 8.1 Introduction to Core Animation

        • 8.1.1 What is Core Animation?

        • 8.1.2 Class structure

        • 8.1.3 Core Animation’s rendering architecture

        • 8.1.4 Creating a basic animation with Cocoa Animation

      • 8.2 Core Animation layers

        • 8.2.1 Layer coordinate systems

        • 8.2.2 Layer geometry

        • 8.2.3 Layer content

      • 8.3 Animating with Core Animation

        • 8.3.1 Basic animations

        • 8.3.2 Keyframe animations

        • 8.3.3 Grouping animations

      • 8.4 Summary

  • Part 3 MacRuby extras

    • 9 HotCocoa

      • 9.1 Introducing HotCocoa

        • 9.1.1 Getting started

      • 9.2 Built-in mappings

        • 9.2.1 Applications and menus

        • 9.2.2 Windows and controls

        • 9.2.3 More advanced layouts

      • 9.3 Building a speech application using HotCocoa

        • 9.3.1 Laying out the views

        • 9.3.2 Making your application speak to you

      • 9.4 Summary

    • 10 MacRuby testing

      • 10.1 Testing MacRuby applications with MiniTest

      • 10.2 Installing and configuring MiniTest

      • 10.3 Application vs. logic testing

      • 10.4 Where to start testing

        • 10.4.1 Application initialization

        • 10.4.2 Core Data

        • 10.4.3 Managing persistence store for testing

        • 10.4.4 Testing predicates

      • 10.5 Summary

    • 11 MacRuby and the Mac App Store

      • 11.1 Introducing the Mac App Store

        • 11.1.1 Benefits of releasing on the Mac App Store

        • 11.1.2 Limitations of the Mac App Store

      • 11.2 Knowing the App Store rules

        • 11.2.1 Functionality

        • 11.2.2 Metadata

        • 11.2.3 Location

        • 11.2.4 User interface

        • 11.2.5 Privacy

        • 11.2.6 Charities and contributions

        • 11.2.7 Legal requirements

      • 11.3 Submitting a MacRuby application

        • 11.3.1 Creating certificates

        • 11.3.2 Registering your Mac App ID

        • 11.3.3 Preparing icons and screenshots

        • 11.3.4 Adding your application to iTunes Connect

        • 11.3.5 Packaging and submitting your application

        • 11.3.6 Dealing with application rejection

        • 11.3.7 Submitting an update

      • 11.4 Summary

  • appendix A: Scripting with MacRuby

    • A.1 Before, there was AppleScript

      • A.1.1 Introduction to AppleScript

      • A.1.2 AppleScript dictionaries

    • A.2 MacRuby scripting

      • A.2.1 Creating a BridgeSupport file

      • A.2.2 Controlling iTunes With MacRuby

      • A.2.3 Updating your iChat status

  • index

    • Symbols

    • A

    • B

    • C

    • D

    • E

    • F

    • H

    • I

    • J

    • K

    • L

    • M

    • N

    • O

    • P

    • R

    • S

    • T

    • U

    • V

    • W

    • X

  • MacRuby-back

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan