Archive for the ‘Programming’ tag
Scott Stevenson interview with Aaron Hillegass
Aaron Hillegass is one of the most famous book authors in the Mac community. The interview can be found here.
Creating a Calculator Class
Creating a calculator class in Objective C is not an easy task! Oh, c’mon sure it
. I’ve been reading about operators lately. Arithmetic operators, bit operators, assignment operators etc. The fact that many of these things were known helps me gap the lack of time to proceed with reading as I wanted too. Here is my last code:
#import <objc/Object.h> #import <stdio.h> @interface Calculator: Object { double accumulator; } // accumulator methods -(void) setAccumulator: (double) value; -(void) clear; -(double) accumulator; // arithmetic methods -(void) add: (double) value; -(void) subtract: (double) value; -(void) multiply: (double) value; -(void) divide: (double) value; @end @implementation Calculator -(void) setAccumulator: (double) value { accumulator = value; } -(void) clear { accumulator = 0; } -(double) accumulator { return accumulator; } -(void) add: (double) value { accumulator += value; } -(void) subtract: (double) value { accumulator -= value; } -(void) multiply: (double) value { accumulator *= value; } -(void) divide: (double) value { accumulator /= value; } @end int main (int argc, char *argv[]) { Calculator *calc; calc = [[Calculator alloc] init]; [calc clear]; [calc setAccumulator: 100.00]; [calc add: 200.00]; [calc divide: 15.00]; [calc subtract: 10.00]; [calc multiply: 5.00]; printf("The result is %g\n", [calc accumulator]); [calc free]; return 0; }
Okay, pretty simple you’ll say! But it’s not! Actually for the first time some things came natural! The allocation and initialisation of memory, I didn’t even think about the right syntax after the first line [calc clear]; which helped write the program quickly. However I made some mistakes the first I wrote the program. The first one was not paying attention that the accumulator was of type “double” and not “void” which caused some warning but not fatal errors
Hello Objective C!
Hello Objective C!
This is my new blog, entirely dedicated in Objective C. I am a starter, never had experience with programming languages, although I was/am able to write small scripts in bash and / or python. Nothing fancy but enough to keep my GNU/Linux tuned!
So a Mac lover with a Linux background in the world of Objective C and object oriented programming! Today I wrote my first program:
Hello world
Surprise ha?
The reason I choose Objective C and not C, Python, Ruby or something else is the cocoa framework which is the best environment I’ve ever seen. I bought 2 books, the first is an extensive guide into Objective C for starters - non programmers - and the second one is an introduction to cocoa framework! I hope that books will speed up the learning process. Due to my work I don’t very much free time but I’ll try to finish the book in a reasonable time.
Cya
[myObject Free];
