Beginning OS X Lion Apps Development

Beginning OS X Lion Apps Development

von: Robert Warner, Michael Privat

Apress, 2012

ISBN: 9781430237211

Sprache: Englisch

387 Seiten, Download: 21195 KB

Format:  PDF, auch als Online-Lesen

geeignet für: Apple iPad, Android Tablet PC's Online-Lesen PC, MAC, Laptop


eBook anfordern

Mehr zum Inhalt

Beginning OS X Lion Apps Development

  Title page 2  
  Copyright page 3  
  Contents at a Glance 5  
  Table of contents 6  
  About the Authors 11  
  Acknowledgments 13  
  Introduction 15  
     The Premise 15  
     The Audience 15  
     How This Book Is Organized 16  
     Source Code and Errata 16  
     How to Contact Us 16  
  Chapter 1 Starting to Build a Graphing Calculator 17  
     Using the Xcode Development Tools 18  
        Obtaining Xcode 18  
        Installing Xcode 19  
        Installing from the Web Download 19  
        Installing from the App Store 25  
        Understanding Xcode 28  
        The Editor Area and the Jump Bar 32  
        The Navigator Area and the Navigator Selector Bar 33  
           The Filter Bar 33  
           The Debug Area and the Debug Bar 33  
           The Inspector Pane, the Inspector Selector Bar, and the Library Pane 34  
           The View Selector 34  
           The Editor Selector 34  
           The Toolbar 34  
     Creating a Project 35  
     Understanding the Major Components 39  
        The Project and Targets 40  
        The Application Architecture 43  
        The Source Code and Resources 44  
        The About Dialog 50  
     Summary 51  
  Chapter 2 Laying Out the User Interface 52  
     Creating the Split View 53  
        Creating the Horizontal NSSplitView 54  
        Creating the Vertical NSSplitView 58  
     Creating the Equation Entry Panel 60  
        Using NSViewController 61  
        Laying Out the Custom Equation Entry Component 63  
        A Primer on Automatic Reference Counting 64  
        Using IBOutlet 65  
        Hooking Up the New Component to the Application 66  
        Resizing the Views Automatically 68  
        Further Customizing the Components 71  
     Creating the Graph Panel 72  
        Adding the Horizontal Slider 73  
        Adding the Table View 75  
        Adding the Graph Panel to the Application 76  
     Creating the Table of Recently Used Equations 77  
        Creating the Data Source 82  
        Displaying the Data 84  
     Adding a Toolbar 86  
     Summary 87  
  Chapter 3 Handling User Input 88  
     Resizing the Views 89  
        Resizing the Window 89  
        Constraining the Split View Sizes 91  
           Constraining the Minimum Size 91  
           Constraining the Maximum Size 92  
        Constraining the Window Size 94  
        Collapsing a Subview 98  
     Handling Button Presses 100  
        The Model-View-Controller Pattern 100  
        Using IBAction 100  
        Creating the Model: Equation 102  
        Communication Among Controllers 105  
     Validating Fields 106  
        Validating After Submitting 106  
           Writing a Validator 107  
           Unit Testing 109  
           Displaying an Alert Window 114  
        A Better Way: Real-Time Validation 115  
           Adding a Feedback Label 115  
           Catching Text Change Notifications 116  
           Wiring It All Together in Interface Builder 117  
     Graphing the Data 119  
        Calculating and Caching the Data 121  
        Talking to the Table: Outlets and Delegates 123  
     Changing the Interval in the Domain 127  
        Using Key-Value Coding 128  
        Binding the Value to the Slider 129  
     Summary 132  
  Chapter 4 Pimp My UI 133  
     Creating a Graph View 134  
        Creating a Custom View 134  
        Linking the New Custom View to the Controller 135  
        Plotting the Graph 138  
           Finding the Boundaries 138  
           Painting the Background 139  
           Plotting the Graph 139  
     Toggling Between Text and Graph 143  
        Adding the Tab View 144  
        Adding the Views to the Tabs 146  
        Switching the Controller to the Tab View 148  
     Creating a Smarter Equation Editor 150  
        Adding Attributes to the Equation Entry Field 151  
        Creating the Tokens 152  
        Parsing the Equation 154  
        Implementing the Method to Tokenize the Equation 156  
           Converting a String to a Token 157  
           Recognizing Numbers 159  
           Grouping Spaces 160  
           Recognizing Trigonometric Functions and Symbols 162  
           Recognizing Exponents 164  
           Creating a Stack for Parenthesis Matching 169  
              Creating the Stack Class 170  
              Testing the Stack Class 171  
              Balancing Parentheses Using Stack 172  
        Detecting Multiple Decimal Points 175  
        Testing the Tokenizer 178  
           Testing Simple Equations 179  
           Testing Exponents 179  
           Testing Whitespace 180  
           Testing Trigonometric Functions and Symbols 181  
           Testing Parenthesis Matching 182  
           Testing Invalid Cases 183  
        Showing the Equation 183  
           Setting the Colors 184  
           Colorizing the Equation 185  
           Superscripting Exponents 187  
        Updating the Validator 189  
        Updating the Evaluator 191  
     Summary 196  
  Chapter 5 User Preferences and the File System 197  
     Managing User Preferences 198  
        Understanding NSUserDefaults 200  
           Persisting Default Values 200  
           Understanding Search Domains 200  
           Resetting Defaults to Reasonable Values 202  
        Setting the Font for the Equation Entry Field 202  
           Responding to Font Changes 205  
           Applying the New Font 207  
        Setting the Line Color 210  
           Understanding Color Selection Modes 211  
           Displaying the Color Selection Panel 212  
           Responding to Color Changes 213  
        Creating a Custom Preferences Panel 215  
           Creating the Preferences View 216  
           Displaying the Preferences Panel 218  
           Using the Custom Preference 221  
     Using the Local File System 222  
        Browsing the File System 223  
           Enumerating Through the Mounted Volumes 223  
           Enumerating Through a Folder 223  
        Writing to the File System 224  
        Reading from the File System 225  
        Exporting Graphs as Images 225  
           Creating an Image from a View 225  
           Adding the Export Graph Menu Item 227  
     Summary 230  
  Chapter 6 Using Core Data 231  
     Stepping Up to Core Data 232  
     Adding Core Data to the Graphique Application 232  
        Adding the Core Data Framework 232  
        Creating a Data Model 235  
        Designing the Data Model 236  
        Initialize the Managed Object Context 243  
     Storing Recently Used Equations 246  
        Querying the Persistent Store to Get the Group Entity 248  
        Creating the Equation Managed Object and Adding It to the Persistent Store 249  
        Committing 249  
        Putting Everything Together into the Final Method 250  
     Reloading Recently Used Equations 251  
     Tightening the Control over the Outline View 257  
        Using NSOutlineViewDelegate 257  
        Handling Equations Selection 258  
        Preventing Double-Clicks from Editing 259  
     Summary 260  
  Chapter 7 Integrating Graphique into the Mac OS X Desktop 261  
     Dealing with Graphique XML Files 261  
        Producing a Graphique File 261  
           Creating a Save As Method 262  
           Grabbing the Current Equation 263  
           Prompting the User to Select a Destination File 264  
           Producing the Graphique File 264  
        Loading a Graphique File into the Application 266  
     Registering File Types with Lion 267  
        Defining the New UTI for the .graphique Extension 267  
        Registering Graphique as an Editor for Graphique Files 269  
        Handling Graphique Equation Files 271  
     Using Quick Look to Generate Previews and Thumbnails 273  
        Creating the Quick Look Plug-in 275  
        Implementing the Preview 278  
        Testing the Plug-in 281  
        Implementing the Thumbnail 285  
        Distributing the Quick Look Plug-in with the Graphique Application 289  
           Copying the Plug-in 290  
     Adding an Item to the Menu Bar 291  
        Understanding NSStatusBar and NSStatusItem 291  
        Adding a Status Item to Graphique 292  
        Building the Status Item Menu 293  
        Integrating the Status Item 296  
        Heeding Apple’s Advice Regarding Menu Bar Icons 298  
           Adding the Preference to the Interface 299  
     Summary 302  
  Chapter 8 Creating Help 303  
     A Word on Help 304  
     Understanding Help Books 304  
     Creating Your Help Book 305  
        Creating the Directory Structure 305  
        Creating the Main Help File 306  
        Creating the Rest of Your Help Files 308  
        Creating the Help Index 311  
        Setting Up Your Plist File 311  
        Importing Your Help Book into Your Xcode Project 314  
        Updating Your Application’s Plist File 315  
     Viewing the Help 316  
     Bookmarking a Page 317  
     Performing a Search 318  
     Summary 320  
  Chapter 9 Printing 321  
     Printing the Graph View 321  
        Printing the Graph 321  
           Implementing the Method to Print 324  
           Wiring the Method to the Menu 324  
           Sizing the Printed View 328  
        Drawing for the Printer 330  
     Spanning to Multiple Pages 332  
        Calculating the Number of Pages 333  
        Determining the Page Size 334  
        Drawing the Page 335  
     Summary 336  
  Chapter 10 Submitting to the Mac App Store 337  
     Reviewing the Guidelines 337  
     Finishing the App 338  
        Terminating Graphique When Its Window Closes 338  
        Adding the Icon 338  
        Reviewing the Property List File 341  
        Cleaning Up the Menu 342  
           Finishing the About Box 342  
           Centering the Preferences Panel 343  
           Removing Unused Menu Items 344  
           Adding a Menu Item for Full-Screen 344  
        Setting the Initial Window Size and Location 345  
        Signing the Code 348  
           Using the Developer Certificate Utility 348  
           Registering Your App IDs 349  
           Installing Apple’s Certificate 351  
           Creating the Provisioning Profile 358  
           Configuring the Build to Sign the Code 362  
        Sandboxing the App 363  
           What Is Sandboxing? 363  
           What Are Entitlements? 364  
           Establishing the Sandbox 365  
        Building for Release 366  
     Setting Up Your Web Site 367  
        Using the Artwork 368  
        Creating the Web Site 368  
     Submitting the App 370  
        Setting Up Your iTunes Connect Account 370  
        Uploading Your Application 371  
           Setting the App Name 371  
           Selecting Availability and Pricing 371  
           Entering Additional Information 371  
              Metadata 372  
              Rating 373  
              EULA 373  
              Uploads 373  
           Performing the Upload 374  
     Summary 377  
  Index 378