Showing posts with label Learn Objective-C. Show all posts
Showing posts with label Learn Objective-C. Show all posts

Thursday, June 28, 2012

Objective-C creating objects, methods and variables

In this tutorial we will be creating a console application to try every part of our code out. Please make sure that the console is not set to its default language, which is C and is instead set to foundation.
The first thing we need to do is create a no project with Xcode. I will be naming mine “test” but you really don’t need to follow along with that much detail since it is not needed at this stage with the level of coding we will be doing.
The next thing we will need to do is open up our “test.m” file through Xcode. This file contains the default main method but we are going to be creating objects and variables.

Wednesday, June 20, 2012

Beginning Objective-C Programming


Table Of Contents
Chapter One: Introduction to ProgrammingChapter Two: If StatementsChapter Three: Switch StatementsChapter Four: LoopsChapter Five: FunctionsChapter Six: Object-Oriented ProgrammingChapter Seven: Introduction to Foundation and UIKitChapter Eight: Essential Foundation ClassesChapter Nine: How To Create Your Own ClassesChapter Ten: Extending Classes with CategoriesChapter Eleven: Protocols in Objective-CChapter Twelve: Key-Value Coding

[Object-C] Chapter 12: Key-Value Coding (KVC)


Another advanced technique is key value coding or KVC. This involves using a set of NSObject methods that can set or get property values based on their string representation. So, if a class has a name property you can get or set that value by using the dot notation in code or you can query the object with the string name to get or set the value.
This is an alternative to the typical way of working with properties that you can use in situations where you may not know the name of the property you will need at the time of writing the code. You may also use KVC to query arrays of objects or even arrays that are properties of an object.

[Object-C] Chapter 11: Protocols In Objective-C


A protocol is a way to require classes to implement a set of methods. We define a protocol much like a class or a category, it is essentially a list of methods. Protocols do not do anything themselves, they are a definition of a type of contract that we can require other classes to implement.
We call that adopting the protocol and we’ve seen this before. You may recall that the application delegate file that XCode created for use included this as part of the application delegate interface:
<UIApplicationDelegate>
This was required because we needed our class to act as an application delegate. This delegation pattern is implemented using protocols because we need a way to require a class to implement a set of methods in order for it to act as a delegate. The code above is how you indicate to the system that a class is adopting a protocol.

[Object-C] Chapter 10: Extending Classes with Categories


Much of the day to day work in object-oriented programming involves using classes that are already written. Sometimes we want our classes to do just a little bit more. That means they need more properties and methods and adding these entities changes the nature of the class. This is called sub-classing and we already covered how to do that.
There are times, however, when we want to extend the abilities of class but we don’t want to define a completely new class. You will encounter these situations more and more as you plunge into Objective-C programming. Perhaps more importantly, you will find examples of category use throughout the Mac and iOS programming examples written by Apple and other developers.
So, to extend a class without sub-classing you have the option of using categories. Let’s talk about how to do this.

[Object-C] Chapter Nine: How To Create Your Own Classes


At some point you will want to define your own classes to use in your app. So now let’s expand on the notion of object oriented programming by showing you how to implement your own custom classes. At this point you should be familiar with using existing objects in code; but you also need to be able to create your own types of objects.

Sub-Classes

One of the most common things that you will be doing with classes is something called sub-classing. As you can guess the iPhone has classes already in place to do things like present data tables, present windows and so on. Usually you will be creating your own object that inherits one of these preexisting objects and adding your own custom code to it. This is sub-classing.

[Object-C] Chapter Eight: Essential Foundation Classes


Now that we have a better handle on how object oriented programming works on iOS we should go over some of the key Foundation classes that you will use in your own apps. Like the name suggests, Foundation supports the key frameworks used in iOS development. Most of what you will be doing when building iOS apps comes from Foundation and will use Foundation classes.

Foundation Inheritance Hierarchy

Remember that classes can have an inheritance relationship with other classes. Although we did not mention it specifically we have already seen classes in Foundation that are in an inheritance relationship. The two classes that I am talking about are NSObject and NSStringNSString inherits from NSObject. You might also say that NSString is a kind of NSObject. Because of this relationship, NSString has all the properties and methods it needs to be and do what an object is.

[Object-C] Chapter Seven: Introduction To Foundation & UIKit


iOS developers use two key object oriented frameworks called Foundation and UIKitto do many of the most important programming tasks needed to make apps. Frameworks are collections of code that are shared by programmers that solve common problems. Foundation was built by engineers to solve common computing problems like using strings, managing collections of objects, connecting to the Internet, storing data, writing to the file system and much more. UIKit is the framework that is responsible for all the visual elements that you see on iOS apps like buttons, tables and tab bars.
I want to go over these frameworks with you in this chapter for two reasons. The first is that the best way to start learning object oriented programming is to see how objects are used in code. You need to learn how to instantiate objects from classes, manage memory with objects and how to use objects. Most of modern programming focuses on using code from frameworks like Foundation to develop software.

[Object-C ] Chapter Six: Object-Oriented Programming


Object oriented programming is a way of thinking about programming in terms of objects. An object in programming is like an object in the real world. That is, an object is something that you can describe and does things. Objects in the real world also have relationships to other objects. That is, an object in the real world may be made up or other objects, use other objects or it may be a variation of another object.
To help understand objects in programming, consider the example of a real world object like a car. You can describe a car as something that has four wheels, a color, model, make and so on. A car also does things like go forward, turn left and stop. Finally, a car is related to other objects in the world. A car is a type of vehicle (which itself is a kind of object), a car is made up on other objects (engine, wheels, stereo system) and a car is used by a person.
This way of describing and organizing things is natural for most of us. We tend to think of the world in terms of objects. In programming, objects are like the car example: an object’s attributes can be described and they can demonstrate behavior. Sometimes objects in programming actually correspond to objects in the real world. Programming objects also have relationships to other programming objects.

[Object-C] Chapter Five: Functions


A function in programming is a discreet area of code that is independent from the rest of the program. Functions are also called subroutines and as that name implies functions are a bit like small programs. Generally, functions may accept variables as inputs and a function may produce a value as an output.
Take a look at figure 1 to see what all the pieces of a function look like before we discuss each piece separately.
Figure 1: Anatomy of a Function

[Object-C] Chapter Four: Loops


Loops are used in programming when we want to repeat a similar task many times. Instead of just writing out each line of code we can use a loop to repeat code for a set number of times or until a condition is met. There are three types of loops that we will be discussing here: for loopwhile loopand do loop.
An example of something that you may want to do in programming that would be repetitive task is counting from 1 to 10. From what you learned in the past chapters you may try to count like this:
int count;
count = 0;
count = count + 1;
count = count + 1;
count = count + 1;
count = count + 1;
count = count + 1;
count = count + 1;
count = count + 1;
count = count + 1;
count = count + 1;
count = count + 1;
Clearly this task is very repetitive and with loops we can write it out in a much better way. Let’s see how to do the simple example above using each type of loop that we have available so far starting with the for loop.

[Object-C] Chapter Three: Switch Statements


switch statements are used when we want to execute different bits of code based on the value of an integer variable. While the if statement from the last chapter gave us two options (either the condition was met or it wasn’t),switch statements give us a way to conditionally execute code with more than two possibilities. Here is the general form that the switch statement takes.
int level = 0;

switch (level) {
     case 0:{
         //execute code when level == 0
         break;
     }
     case 1:{
         //execute code when level == 1
         break;
     }
     case 2:{
         //execute code when level == 2
         break;
     }
     default:{
         //execute code if level does not
         //meet any of the conditions above
         break;
     }
}

[Object-C] Chapter Two: If-Statements


If statements are used to execute code based on whether a condition is present in the state of the program. Simply put, an if statement is a way for us to tell a computer to do something if a condition is met and something else if the condition is not met. Below is the general form that an if statement takes.
BOOL condition = YES;
if(condition){
     //take action when condition is YES
}
else{
     //take action when condition is NO
}
The if statement above has three important components: the test to see if the condition is true, the code that will execute if the condition is true and the code that will execute if the condition is false.

[Object-C] Chapter One: Introduction to Programming


Programming is the process of giving instructions to a computer. Apps on your iPhone work because someone took the time to write instructions that have been packaged into an app that you download and use on your iPhone.
Here’s an example of how you would give instructions to an iPhone app. The code below will show us a alert that says Hello World:
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Alert View"
                                                    message:@"Hello World"
                                                   delegate:nil
                                          cancelButtonTitle:@"Ok"
                                          otherButtonTitles:nil];
[alertView show];
The code above will present an alert view to the user with the text Hello World. See figure 1.1 below for an example.
Figure 1.1 - Hello World
These instructions probably don’t make much sense to you yet but that’s ok – this book is all about how you can use instructions like this to get things done in your apps.

Monday, June 18, 2012

Integrate PhoneGap with Zxing for iOS - Barcode Scanner - Xcode 4

I spent a long time to config them. so tired, but now it run very good. It's work.

Step 1: 

Download Source PhoneGap at PhoneGap.com ( version 1.8.0 or higher )
after downloaded => install it and follow with introduction

Step 2: 

Download Source barcodescanner  at:
https://github.com/phonegap/phonegap-plugins/tree/master/iOS/BarcodeScanner

Friday, June 8, 2012

Learn Objective-C: Day 6


In today’s tutorial, you will learn about Categories and how to use them to extend the functionality of Cocoa-Touch classes. This is our final installment in the Learn Objective-C series, so you will also be provided with a quick recap on what we’ve covered so far and then look at what you can do to further your skills as an Objective-C or iPhone application developer.

Learn Objective-C: Day 5


Welcome to part five of this series on Objective-C. Today we’re going to look at memory management, an element of Objective-C (and many other languages) that tends to trip up newer programmers. Most scripting languages (such as PHP) take care of memory managaement automatically, but Objective-C requires that we are careful with our use of memory and manually create and release space for our objects.
It’s good practice to keep track of how much memory your application is using, so you don’t encounter any leaks or hog up the memory on the system. It’s even more important on mobile systems such as the iPhone where memory is much more limited than on a desktop machine.

Thursday, June 7, 2012

Learn Objective-C: Day 4


Welcome to part four of this series on Objective-C. So far, we’ve looked a lot at theory and the principles and functionality of the language to get a good idea of how it works. Today, we will be making a simple class similar to the car example we looked at in previous parts of this series. Our class will take the details of a car, allowing us to get and set the values held. After today’s example you should be able to create your own classes in Xcode and toy around with them.
So far, we have had some great feedback via email, twitter and comments. Itʼs great to see so many people are interested in this subject and itʼs even better to see that so many of you are trying it out for yourself and asking some great questions. Keep it up!

Learn Objective-C: Day 3


Welcome to part three of this series -I hope youʼre enjoying it! Last week we looked at how we separate classes in to separate files (interface and implementation), this week weʼre going to look at classes again, but a little bit more in depth. Weʼll also take a peak at inheritance and how it works, along with variable scope.
So far, we have had some great feedback via email, twitter and comments. Itʼs great to see so many people are interested in this subject and itʼs even better to see that so many of you are trying it out for yourself and asking some great questions. Keep it up!

Learn Objective-C: Day 2


Welcome to part two of this introductory series on Objective-C. After spending last week reviewing the fundamentals of the C language upon which Objective-C is built, this week we will transition to focusing on what makes Objective-C such a great language for software development. Specifically, we will discuss the fundamentals of Object Oriented Programming (OOP) and demonstrate how to create a class and send messages to objects in Objective-C.

Popular Posts