Showing posts with label objective-c. Show all posts
Showing posts with label objective-c. Show all posts

Monday, January 13, 2014

For-Loop in Objective-C


So , I bought this book yesterday.

And what I plan on doing is once or twice a week blogging about a chapter or two whilst I relearn objective-c.  We basically covered the first* chapter last week with classes , objects and methods. Go us. So let us start on chapter 2.
*First chapter actually about code

----------------------------------------------------------------------------------------------------------------------------

*Recapping the previous chapter*

So last chapter we learned all about Data-types , objects , methods and classes.

Type float
float  floatingVar = 123.21;
Type int
int integerVar = 19;
Type double
double doubleVar = 2.923e+11
Type char
char charVar = ‘h’
Type id
id hannahObject;

*Recap Over*


So this chapter we are going to talk about looping in objective -c

     There are three different types of ways to loop in Objective-c
  • For Loop
  • While Loop
  • Do statement
But We are only covering For loops today.

----------------------------------------------------------------------------------------------------------------------------

Say we wanted to know the sum of all numbers to 150?
    ex. 1+2+3+4......+150

You could individually add all the numbers but that doesn't seem like it would be very efficient. As we are programmers and we are lazy and that's just wayyy tooo much typing.

This is how you would execute the different loops finding the sum of all numbers to 150.

For loop
#import<Fountdation/Foundation.h>

int main ( int argc , char * argv[])
{
  @autoreleasepool{
     int n , sumNumber;
sumNumber = 0;
for (n = 1; n<=150; n = n+1)
sumNumber += n;

NSLog(@”The sum of the numbers is %i” , sumNumber);

   }
return 0;
}
The format of a for loop is

for( init_expression ; loop_condition; loop_expression)
program statements

The three expressions inside of the parentheses are the expressions that control the for loop.

init_expression: used to set up values before the loop begins. (ex. N = 1; )
loop_condition: Used to state the conditions for the loop to execute. (ex. N<= 150;)
loop_expression: This is evaluated after each time the program statements have been executed. (n = n + 1;)

This is a very basic explanation of for loops. For Loops can be very powerful when used correctly. But you must be careful not to fall into the infamous infinite loop. This is when your loop condition is never met and causes the loop to run forever.

Tomorrow I will chat about While loop!

Wednesday, January 8, 2014

Just a quick Objective - C Overview

Right , I promised myself that I would keep to my blog schedule I have planned. But I don't think adding more content is a bad thing. So here is my third blog for the day. *sweet baby rays*

So , I have an interview tomorrow and I am going to brush up on my Objective-C and iPhone development. *these posts are going to be really embarrassing if I don't get the job.. yikes oh well*  And when I teach what I am learning it sticks better so buckle up you're about to learn some Objective-C. *confetti falls from celling*






Alright first off, what is Objective-C?

  • Objective-C is most often used whenever you are programing in the iOS or the OS X operating systems. 
  • Objective-C also provides object-oriented capabilities and dynamic runtime
Fancy stuff. So in non technical terms , Objective-C is mostly used in Apple products , and the dynamic run time means that objective-c decides which method implementation to call right before calling it. 

COOL.. movinggggg on...

Let's do some code together shall we? 

To start off we will cover some basic syntax -

A Class- 
 *NOTE CLASS NAMES MUST BE UNIQUE.. like you ;)
So a class is simply called by typing the following :
--> @interface HannahClass : NSObject
--> End

 Righto simple enough. Next step is we are going to document name and twitter handle. These are called properties. They're called like this.

@interface HannahClass : NSObject

@property NSString *name;
@property NSString *handle; 

end

Sweet. So now our app uses the class Hannah and has two string properties within it that holds my name and my twitter handle.
  • please note that we use the asterisk to indicate that they are c-pointers. So basically memory stuff.
The following two lines are for int and num declarations. So we are going to add birth day and birth year.

@property NSNumber *birthDay;
@property int *birthYear;

Right. Noted that int isn't an NS because I fudged that up the first time. *thehe*

How to call a method. SIMPLE.. I got this..

-->  (void)someMethod; 

BOOM. That's how it's done. Yes yes I realize that if you're coding on a mac and using XCode it most likely autocompletes this for you but ya know. WHAT IF YOUR XCODE JUST DIES AND YOU SUDDENLY NEED TO CODE BUT YOU CAN'T USE XCODE. Hmmm that's what I thought.

Much like any other language methods can take parameters. 

-->  (void)someMethod : (someType) value;

Same thing but with more than one param -
--> (void)someMethodWithFirstValue :(SomeType)value1 secondValue:(AnotherType)value2;

cool beans..

I think that's enough review for the moment as I am very tired. BUT.. I wish all of you a happy day! If anyone reads this far haha.


*disclaimer : The source i used for objective-c was here












Saturday, January 4, 2014

Classic First Post

Well , Hello!  I guess for the first post I will just let you know a bit about myself. My name is Hannah, and I currently reside in Colorado. I recently , May 2013 , graduated from Colorado State University - Pueblo with a degree in Computer Information Systems with an emphasis in programming. I was also apart of the women's soccer team during my time at CSU-P. I currently work for a company called Intelligent Software Solutions out of Colorado Springs. I am a Software Engineer in Test and I love it! I create automated tests for nearly all the applications that our company engineers.

Some of the languages that I have worked with are :
  1. Ruby
  2. Java
  3. C#
  4. JavaScript 
  5. Objective - C
I plan on learning much more!
I am creating this blog in order to keep myself sane , and give me a electronic place to keep my thoughts because I cannot read my own handwriting on occasion.

If you're feeling adventurous add me on twitter and we can tweet each other !

Hope to chat to you soon!

-Hannah