Application Programming on the Mac COSC346



Similar documents
How To Develop An App For Ios (Windows)

Objective C and iphone App

An Introduction to Modern Software Development Tools Creating A Simple GUI-Based Tool Appleʼs XCode Version 3.2.6

MA-WA1920: Enterprise iphone and ipad Programming

INTRODUCTION TO IOS CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 13 02/22/2011

Application Menu and Pop-up List Programming Topics

Contents. About Testing with Xcode 4. Quick Start 7. Testing Basics 23. Writing Test Classes and Methods 28. At a Glance 5 Prerequisites 6 See Also 6

Model-View-Controller (MVC) Design Pattern

ios Dev Crib Sheet In the Shadow of C

Mobility Introduction Android. Duration 16 Working days Start Date 1 st Oct 2013

Introduction to iphone Development

Start Developing ios Apps Today

Ruby and Python Programming Topics for Mac. (Retired Document)

ios Development Tutorial Nikhil Yadav CSE 40816/60816: Pervasive Health 09/09/2011

View Controller Programming Guide for ios

Cocoa Fundamentals Guide. (Retired Document)

Common Lisp ObjectiveC Interface

Programming Cocoa with Ruby Create Compelling Mac Apps Using RubyCocoa

Learn iphone and ipad game apps development using ios 6 SDK. Beginning. ios 6 Games. Development. Lucas Jordan. ClayWare Games tm

geniusport mobility training experts

2. About iphone ios 5 Development Essentials. 5. Joining the Apple ios Developer Program

INTRODUCTION TO OBJECTIVE-C CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 12 09/29/2011

Creating Carbon Menus. (Legacy)

WebObjects Web Applications Programming Guide. (Legacy)

This documentation is made available before final release and is subject to change without notice and comes with no warranty express or implied.

Chapter 1. Introduction to ios Development. Objectives: Touch on the history of ios and the devices that support this operating system.

How to install and use the File Sharing Outlook Plugin

FUGU - SFTP FOR MACS- REFERENCE GUIDE

Kevin Hoffman. Sams Teach Yourself. Mac OS* X Lion" App Development. 800 East 96th Street, Indianapolis, Indiana, USA

GUI and Web Programming

geniusport mobility training experts

Title: Appium Automation for Mac OS X. Created By: Prithivirajan M. Abstract. Introduction

CSCI E-65: Mobile Application Development Using Swift and ios

Assignment I Walkthrough

Developing Applications for ios

Creating Home Directories for Windows and Macintosh Computers

IOS App Development Training

Development of an iphone business application

The Desktop Sharing Handbook. Brad Hards

Event processing in Java: what happens when you click?

Send from your App Part 1

MiniDraw Introducing a framework... and a few patterns

NSPersistentDocument Core Data Tutorial for Mac OS X v10.4. (Retired Document)

eggon SDK for ios 7 Integration Instructions

Mobile App Design and Development

OPERATING SYSTEM SERVICES

Praktikum Entwicklung von Mediensystemen mit

Mail 8.2 for Apple OSX: Configure IMAP/POP/SMTP

Mac System Setup Guide (Pre-Class)

How To Use An Apple Macbook With A Dock On Itunes Macbook V.Xo (Mac) And The Powerbar On A Pc Or Macbook (Apple) With A Powerbar (Apple Mac) On A Macbook

Client Requirement. Master Data Management App. Case Study -

Chapter 1. Xcode Projects

Assignment # 2: Design Patterns and GUIs

Admin. Mobile Software Development Framework: Android Activity, View/ViewGroup, External Resources. Recap: TinyOS. Recap: J2ME Framework

Implementação. Interfaces Pessoa Máquina 2010/ Salvador Abreu baseado em material Alan Dix. Thursday, June 2, 2011

Using the Synchronization Client

2. Create the User Interface: Open ViewController.xib or MainStoryBoard.storyboard by double clicking it.


Example of Standard API

Select the name of the application and click on Force Quit.

System Architecture V3.2. Last Update: August 2015

ICP Data Entry Module Training document. HHC Data Entry Module Training Document

Specialized Android APP Development Program with Java (SAADPJ) Duration 2 months

HHC Compensation Module Training Document

The presentation explains how to create and access the web services using the user interface. WebServices.ppt. Page 1 of 14

Using the Caché Objective-C Binding

vtcommander Installing and Starting vtcommander

Getting Started with Android Programming (5 days) with Android 4.3 Jelly Bean

Customize Mobile Apps with MicroStrategy SDK: Custom Security, Plugins, and Extensions

E4 development: examples, methods and tools. Eclipse Con France 2014

Mac OS X guide for Windows users

Viewing LogicalCHOICE ebook/epub Files

Beginner level: Modules 1 to 18. Advanced level: Quick review of modules 1 to 18, then following to module A Simple ios Application

Frameworks & Android. Programmeertechnieken, Tim Cocx

lubyk lua libraries for live arts Gaspard Bucher (Buma)! artist, musician, coder

Programming IoT Gateways With macchina.io

Client Configuration Guide

Xcode Application note

Shellshock Security Patch for X86

VT Technology Management Utilities for Hyper-V (vtutilities)

Guest PC. for Mac OS X. User Guide. Version 1.6. Copyright Lismore Software Systems, Ltd. All rights reserved.

5nine Hyper-V Commander

How to Develop Accessible Linux Applications

Android Mobile App Building Tutorial

Game Center Programming Guide

Xcode Project Management Guide. (Legacy)

Creating XML Report Web Services

Launch Time Performance Guidelines. (Legacy)

GUIs with Swing. Principles of Software Construction: Objects, Design, and Concurrency. Jonathan Aldrich and Charlie Garrod Fall 2012

Initial Setup of Microsoft Outlook 2011 with IMAP for OS X Lion

Automated Performance Testing of Desktop Applications

Transcription:

Application Programming on the Mac COSC346

OS X Application An application is a complex system made of many subcomponents Graphical interface Event handling Multi-threading Data processing Storage 2

Cocoa Environment Cocoa is a collection of frameworks & libraries. Key parts: AppKit Provides a set of elements for GUI: windows, views, buttons, Provides controllers that glue model & views together Abstracts away most of the logic under-the-hood such as the mouse and keyboard event handling, etc. Core Data Abstracts away data storage Options for XML, binary files, or SQLite database for storage Foundation Framework Library for custom logic binding all the other elements together 3

One Pattern to Rule them All User action Controller Update View Model Update Notify Model-View-Controller (MVC) Model information storage View interface that allows user to interact with information Controller coordinates interaction between view & model Sole purpose: decouple view & model as much as possible Cocoa Framework heavily utilises the MVC pattern 4

AppKit 5

Application types Single-window utility app Single-window library-style app Multi-window document-based app 6

Single- window app 7

NSApplication class Every Cocoa application runs exactly one instance of an NSApplication object Manages the lifecycle of an application NSApplication is a singleton Instantiated and run from the main function of your program executable NSApp is a global reference for the NSApplication object instance Handles the loading of GUI at the start and keeps track of windows For instance, which window has the user focus Runs the main event loop Collects and dispatches application events, such as user input Handles redrawing Your program becomes a delegate of the NSApplication object instance, called after the application is loaded 8

NSApplication class To get a reference to the running application let application = NSApplication.sharedApplication() or let app = NSApp as! NSApplication Has methods for: Terminating the application Maximising/minimising/hiding windows Updating windows Managing menus 9

XIB and NIB XIB Xcode/XML Interface Builder The XML file in your Xcode project that contains description of all the visual components added in the Interface Builder The interface shown in the Interface Builder is a rendering corresponding to this file You do not edit this file directly when you modify your app s interface in the Interface Builder, the contents of XIB will change NIB The compiled code corresponding to the XIB file This is a binary file that saves all the objects corresponding to the AppKit s classes specified in the XIB file This file becomes part of your application bundle, but you never access it directly the application will load it automatically when it starts 10

Application bundle contents Executable file that starts the application OS X hides the fact that the bundle is a directory it looks just like a single file Clicking on.app bundle runs the executable code in the bundle NIB file This file stores all the graphical elements from Xcode s Interface Builder that are part of your application When your application starts, NIB is one of the first things to get loaded Other files that you included in your Xcode project Images, media, etc. You can access these resources by loading them from the main bundle the path of the bundle can be derived from the NSBundle object corresponding to your application bundle 11

Default Cocoa application NSView AppDelegate applicationdidfinishlaunching() window window contentview delegate NSApp NSWindow NSApplication mainwindow NSMenu mainmenu Encoded in the XIB Application source code 12

Custom Cocoa application AppDelegate NSButton target: AnyObject? action: Selector enabled: Bool superview subviews[0] NSView applicationdidfinishlaunching() window window window contentview delegate NSApp NSWindow NSApplication mainwindow NSMenu mainmenu Encoded in the XIB Application source code 13

Application Delegate Code to control your application goes in the AppDelegate.swift file 14

Application Delegate Application delegate serves the NSApplication object Application delegate subscribes to the NSApplicationDelegate protocol, which contains optional methods for Launching, terminating, managing the active status, and hiding your application Managing windows and dock actions associated with your application. Opening and printing files. Your code should be placed in the applicationdidfinishlaunching: method, which gets invoked by NSApplication after it s done loading the GUI from NIB 15

Application execution After each object is unarchived from the NIB file and connected (via actions and outlets), it is sent an awakefromnib message. 16

Main event loop Waits for events from the OS and dispatches them to appropriate handlers The autorelease pool is drained after each pass through the event loop When the application terminates, your objects are destroyed 17

NSRunLoop class You can get a reference to the main loop running in the NSApplication instance as follows: let loop = NSRunLoop.currentRunLoop() Reference to the current loop is useful for adding timers and communication ports 18

Interface Builder Xcode s GUI for creating Cocoa Applications You can design the look of you application by dropping various visual elements in the application window You can connect graphically various visual elements to your application Target and Action connect controls to code that is invoked when user interact with the control Outlets references in your code to various visual elements, so that they can be controlled programmatically 19

Outlets How do you reference in your code the objects corresponding to the UI elements created in the Interface Builder? In Cocoa, these references are called outlets When you create a single-window project, the application delegate gets automatically setup with an outlet called window, which is a reference to the main window object of your application In the interface definition for the class, which is going to contain a reference to a given UI object, define a weak var preceded by the @IBOutlet annotation The @IBOutlet annotation does not change anything in terms of the program, except for being a special marker for the Interface Builder for keeping track of outlets In Interface Builder you can control-click a UI element and connect it to an outlet 20

Outlets 21

Targets and Actions What do you want to happen when a user clicks on a button, or a slider, or a checkbox, or other UI control element? Create an action it is a method that implements the logic in response to a user interacting with a control element An action method is any method that returns nothing and accepts one parameter (identifying the sender) The object implementing the action for some control element is referred to as the target 22

Targets and Actions Connection of UI elements to corresponding targets and actions can be done graphically in the Interface Builder In the interface for the target class specify an action method using the @IBAction annotation The @IBAction annotation is used by the Interface Builder to indicate an action method In the Interface Builder control-click a UI element and connect it to a specific action 23

Targets and Actions 24

Custom Cocoa application AppDelegate target NSButton target = respondtoclick() action: Selector enabled: Bool superview subviews[0] NSView applicationdidfinishlaunching() respondtoclick(sender) mybutton window window window contentview delegate NSApp NSWindow NSApplication mainwindow NSMenu mainmenu Encoded in the XIB Application source code 25

Summary In this lecture we examined the anatomy of the default Cocoa application. We have also covered the outlet, target and action mechanism which connects GUI object to the code that dictates their behaviour. NSApplication singleton class that runs your application NSApplicationDelegate protocol for application delegate with methods for handling various application events XIB/NIB file storing the visual elements NSLoop event loop class, useful for running timers @IBOutlet annotation that lets Interface Builder know that following pointer is a reference to a GUI element @IBAction annotation that lets Interface Builder know that following definition is a an action method to be invoked when a user interacts with a GUI control element 26