Amazon.com Widgets Method to create new objects
Welcome, Guest. Please login or register.
Did you miss your activation email?
June 19, 2013, 07:06:14 AM
Home Help Search chat Login Register   
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+  Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+  Programming in Objective-C, 4th edition
| |-+  General Discussion
| | |-+  Method to create new objects
Pages: [1]   Go Down
Print
Author Topic: Method to create new objects  (Read 257 times)
JeroenJK
Newbie
*
Posts: 40







« on: May 20, 2013, 12:37:59 AM »

Product.h:

Code: (Objective-C)
#import <Foundation/Foundation.h>

@interface Product : NSObject
{
    unsigned int valueOfProducts;
}

-(void) increaseValueOfProducts;
-(void) decreaseValueOfProducts;
-(void) resetValueOfProducts;

@end
Product.m:

Code: (Objective-C)
#import "Product.h"

@implementation Product

-(void) increaseValueOfProducts {
    valueOfProducts += 1;
}

-(void) decreaseValueOfProducts {

    if ( valueOfProducts > 0 ) {
        valueOfProducts -= 1;
    }
}

-(void) resetValueOfProducts {
    valueOfProducts = 0;
}

@end
main.m:

Code: (Objective-C)
#import "Product.h"

int main(int argc, char *argv[])
{
    @autoreleasepool {

        Product *sandwich = [[Product alloc] init];
        Product *coke = [[Product alloc] init];
        Product *chips = [[Product alloc] init];
        Product *bread = [[Product alloc] init];

    }
}
Now is my question: Is there any method, or something, that I can add so the user can add objects (so, new products) to the program he wants to keep track of?

I don't remember I have had that in the book, and I don't know what to search for. So I hope someone can help me with this.

Many thanks to anyone responding!
Logged

Just started learning Objective-C (fourth edition), so don't expect too much from me. Wink
Pages: [1]   Go Up
Print
Jump to:  



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.