Objective-c the use of creating classes

Source: Internet
Author: User

Here is an example I wrote to test how Objective-c uses the class's

TestClass.h

  testclass.h//  testclass////  Created by exchen on 6/15/15.//  Copyright (c) exchen. All rights reserved.//#import <Foundation/Foundation.h> @interface testclass:nsobject{    //public member variable    @ public    int number1;    int number2;    NSString *nstr;    Char strarray[20];} member function declaration-(void) print;-(void) calc;-(nsstring*) Strappend: (nsstring*) string1: (nsstring*) string2; @end

Testclass.m

  testclass.m//  testclass////  Created by exchen on 6/15/15.//  Copyright (c) exchen. All rights reserved.//#import "TestClass.h" #import <stdio.h> @implementation testclass//member function implementation-(void) print{    printf ("%d\n", number1);    NSLog (NSTR);    printf ("%s\n", Strarray);} -(void) calc{    number1 + = number2;    printf ("%d\n", Number1);} -(nsstring*) Strappend: (nsstring*) string1: (nsstring*) string2{nsstring    *strret = [string1 STRINGBYAPPENDINGSTRING:STRING2];    return strret;} @end

Main.m

  main.m//  testclass////  Created by exchen on 6/15/15.//  Copyright (c) exchen. All rights reserved.//#import <Foundation/Foundation.h> #import "TestClass.h" int main (int argc, const char * argv[] {    @autoreleasepool {        //Insert code        here ... NSLog (@ "Hello, world!");    }        TestClass *TC = [[TestClass alloc] init];  allocating memory        tc->number1 = 1;  Assigning a value to a class member variable    tc->number2 = 2;    [TC Calc];       Call the class member function        strcpy (Tc->strarray, "Strarray");   Assigning a value to a class member string variable        [TC print];  Call the class member function        nsstring *strret = [TC strappend:@ "string1": @ "string2"];  Call a function with parameters    NSLog (strret);//print return value returned    0;}

Engineering

Objective-c the use of creating classes

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.