Creating a Custom Class in Xcode



Similar documents
ios App Development for Everyone

ios App Development for Everyone

Praktikum Entwicklung von Mediensystemen mit

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

iphone Objective-C Exercises

Assignment I Walkthrough

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

Xcode Application note

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

Objective C and iphone App

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

ios Dev Crib Sheet In the Shadow of C

MA-WA1920: Enterprise iphone and ipad Programming

ios Dev Fest Research Network Operations Center Thursday, February 7, 13

M, N, O F, G, H. network request, 101 ParseFacebookUtilities SDK, 100 profile, 100 user_about_me, 101 -(void)updateindicator, 101

ios Application Development &

Your First ios Application

Star Micronics Cloud Services ios SDK User's Manual

Chapter 1. Xcode Projects

Developing Applications for ios

Introduction to Objective-C. Kevin Cathey

Xcode Project Management Guide. (Legacy)

Object Oriented Programming and the Objective-C Programming Language 1.0. (Retired Document)

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

Knappsack ios Build and Deployment Guide

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

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

Start Developing ios Apps Today

ios App Development for Everyone

ADITION ios Ad SDK Integration Guide for App Developers

ios Development: Getting Started Min Tsai March 1, 2011 terntek.com v1.0

iphone SDK Enrolled students will be invited to developer program Login to Program Portal Request a Certificate Download and install the SDK

View Controller Programming Guide for ios

Mobile Application Development

Your First App Store Submission

INFORMATION TECHNOLOGY EDUCATION PROGRAMMING AND ANALYSIS COURSE SYLLABUS. Instructor: Debbie Reid. Course Credits: Office Location:

COLLIN COLLEGE COURSE SYLLABUS

by Aaron Hillegass and Mikey Ward

1 от :45

Objective-C and Cocoa User Guide and Reference Manual. Version 5.0

Introduction to iphone Development

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

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

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

Accessibility on ios. Make an app for everyone. Chris Fleizach ios Accessibility. Wednesday, December 1, 2010

A product of Byte Works, Inc. Credits Programming Mike Westerfield. Art Karen Bennett. Documentation Mike Westerfield


How To Develop An App For Ios (Windows)

Tag Specification Document

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

Assignment 2: Matchismo 2

Developing Applications for ios

eggon SDK for ios 7 Integration Instructions

El Dorado Union High School District Educational Services

setup information for most domains hosted with InfoRailway.

Send from your App Part 1

Appendix K Introduction to Microsoft Visual C++ 6.0

Unique Capability 2 Unique App. winchesterinnovation.co.uk

Introduction to Java Applets (Deitel chapter 3)

SPSS Workbook 1 Data Entry : Questionnaire Data

Pcounter Mobile Guide

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

Introduction to Programming with Xojo

Brother ScanViewer Guide for ios/os X

Softwareprojekt: Mobile Development Einführung Objective-C. Miao Wang, Tinosch Ganjineh Freie Universität Berlin, Institut für Informatik

ios App for Mobile Website! Documentation!

Building Mobile Applications Creating ios applications with jquery Mobile, PhoneGap, and Drupal 7

Java (12 Weeks) Introduction to Java Programming Language

From C++ to Objective-C

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

Mercury VirtualTerminal ios Application

1:1 ipad Program Device Setup Guide

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

Programming Cocoa with Ruby Create Compelling Mac Apps Using RubyCocoa

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

Assignment 1: Matchismo

MEAP Edition Manning Early Access Program Hello! ios Development version 14

Sophos Mobile Control Startup guide. Product version: 3.5

Mobile Application Development ITP 342 (3 Units)

2: Entering Data. Open SPSS and follow along as your read this description.

Arduino Training - Basics of Micro-controllers Programming Basics

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Quick View. Folder Details

Creating a 2D Game Engine for Android OS. Introduction

Praktikum Entwicklung von Mediensystemen mit ios

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

IQProtector Mobile Application

Please note that this SDK will only work with Xcode or above. If you need an SDK for an older Xcode version please support.

Mobile App Design Project #1 Java Boot Camp: Design Model for Chutes and Ladders Board Game

Guide 3 - SkyDrive Pro

Swift for PHP Developers

Application Development for Mobile and Ubiquitous Computing

Mobile Print/Scan Guide for Brother iprint&scan

Using Windows Movie Maker to Create Movies

Hello Swift! ios app programming for kids and other beginners Version 1

Cocoa Fundamentals Guide. (Retired Document)

Development of Computer Graphics and Digital Image Processing on the iphone Luciano Fagundes

CSCI 253. Object Oriented Programming (OOP) Overview. George Blankenship 1. Object Oriented Design: Java Review OOP George Blankenship.

Microsoft Tag Scanning SDK for iphone & Android Apps

geniusport mobility training experts

Transcription:

Creating a Custom Class in Xcode By Mark Mudri March 28, 2014 Executive Summary: Making an ios application requires the use of Xcode, an integrated development environment (IDE) developed by Apple. Within the interface there are many premade classes and objects. When developing an application for a specific purpose, these premade tools may not perform exactly how the programmer wants. Therefore, it is useful to make a new class or object to suit the needs of the program. This is an overview of making custom Classes. Keywords: Xcode, Custom Class, Objective C Programming, Object.

Table of Contents Introduction.3 Background..3 Create a Class 4 Conclusion 7 References 8 2

Introduction Xcode is the main tool for programming ios applications. It is an integrated development environment (IDE) developed by Apple that has many user friendly attributes such as a storyboard interface, code composer, compiler, and simulator. The programming language used is objective-c. This is an object oriented language that allows for creative user interactions. Within Xcode and the objective-c language there are a number of predefined classes. While these are very useful, creating a unique application requires manipulation of these classes for the improvement of the functionality or appearance of the application. Background Before creating a custom class, some basic information is needed. An object is something that can be described by attributes. It can be an image, storage or a tool for performing calculations. The attributes can describe the look and how the object act when interfacing with a user or another object. A classification groups objects with the same type of attributes. For example, a person named Bill can be described by his name and age. Every person is different, but they can be described with the same descriptors. In this example, a person is the class and Bill is an object of that class. Name and Age are attributes that can be used to describe any person. The attributes can be the same or different for another instance of the class person. Classes in objective C can also have subclasses inside them. This means that they will be the main class called Super Class will contain basic data and subclasses. The subclasses will contain more specific data than the main class. Continuing on the example started the Super Class person could contain the subclass for male and female specific data. The subclass inherits attributes from the superclass in a hierarchy form. A few other terms that are important to know are an operation and a method. An operation is a procedure that an object performs or has performed to it. An operation of a specific class is a method. 3

Creating a Class To make a new class in Xcode it is advised to make a new file separate from the other code and call the class. This can be done by making a new file. To make a new file, click on File, and then New à File. A selection screen will come up, for an iphone app, select cocoa touch and objective C class. The next screen a name of the new class is entered and an existing class to inherit the attributes from is chosen from a drop down menu. For an object use NSObject. On the main page in Xcode a header and a source file are created and displayed for coding. A class needs two pieces: interface and implementation. The interface is set up in the header file and this tells how exactly the object will interact with other objects and the user. The implementation is written in the source file. This will contain the executable code for each method declared in the interface. The header file is imported by the code #import mmperson.h at the top of the source file. Now that there is a class, it needs the attributes to be declared. In the header file in between the line @interface mmperson: NSObject and @end, the attributes name and age are declared. In objective C, these are declared by stating them as properties of an objective C class. The class for each kind of data is used. Name is declared as an NSString property. Age will be 4

declared as an NSNumber. The code looks like this @property (nonatomic, strong) NSString *name; Also in the header file an initializer method will be created. The code coming up makes use of the alloc and init methods. These methods are in contained in all classes. They are used for memory purposes. The alloc method is a class method that every class has. It returns a pointer to a new instance that needs to be initialized. An uninitialized instance may exist in memory, but it is not ready to receive messages. The init method is an instance method that every class has. It initializes an instance so that it is ready to work. Also in the header file, methods can be declared. Putting in this line of code after the property declarations initializes an instance of the class person: - (id)initwithname: (NSString *)name andage:(nsnumber*)age; More istances can be declared, but for simplicity and observation. The last line of code added in the header file is a method for our object that will describe the object as a string with the attributes. The actual actions will be added into the source file. In the source file, repeat the initialization line from the header file only delete semicolon and add some curly brackets. Inside we can put what happens when the object is called in this instance the file will return a variable called self that contains the name and age of the person. Below that we will add the actual function of the description call. This will return a string that says Person1, name is age. The code for this is [NSString stringwithformat:@ Person1,%@ is 5

%@,self.name, self.age]; This will work for our first class. Now the class is finished, we can make a call of the class and see the result. For the display of the class, a viewcontroller is needed with a single Label that is big enough to hold the string that is returned from the mmperson class. In a simple one view app open drag a label from the list of available objects. The code for the viewcontroller files are shown below. Make sure to import the class using #import at the top of the source file. Notice the instance of mmperson entitled *person1. The code shown allows memory to store the name, Bill, and his age, 32. The line after this declared instance changes the text in the label to display the description of the object. 6

Conclusion The output is as expected. The class can now be used throughout the application. Review of the process, Open a new class with NSObject as the basis for the new class. Declare the properties of the new class in the header file, and any actions that the object will perform. Then in the source file code in the actual actions and what the returns will be. That s the simple version of how to create a Custom class. 7

1. Hillgass, Aaron and mikey Ward. Objective C Programming: The Big Nerd Ranch Guide 2 nd edition. 2. Keur, Christian, Aaron Hillgass and Joe Conway. ios Programming: The Big Nerd Ranch Guide 4 nd edition. 3. Apple Developer. Programming with Objective-C 8