0

I'm new to iPhone development,I want to assign one class in existing class

This is what declare in C#

public partial class UserRegisteration : System.Web.UI.Page
{
//some methods

public class Mime
{
//some methods
}
}

like the above format in Objective-C how to assign one more class in existing class?

Any ideas? Thanks in advance.

user2439531
  • 131
  • 1
  • 2
  • 7
  • Do you mean you want to add some additional properties to an existing class , add additional methods to it? – Zen Jun 06 '13 at 09:38
  • I want to add one class in an existing class – user2439531 Jun 06 '13 at 09:41
  • I'm not sure your question is very clear. Are you asking how to inherit from another class like `@interface myObject : NSObject` or do you want to know how to add something like a string to a class like `@property (nonatomic, strong) NSString *myString;`? – Popeye Jun 06 '13 at 09:42
  • Please can you make it more clear of what you want as this really isn't clear what your after? – Popeye Jun 06 '13 at 09:49
  • 1
    Based on the answer you have accepted the terminology you are looking for is not `assign a new class in existing class` it is called `Inheritance` and `subclassing`. `Inheritance` and `subclassing` play a huge part in programming my I recommend reading up about it. – Popeye Jun 06 '13 at 09:57

2 Answers2

1

Yes you can.I am using one class in existing class . One is extending UIView and other is extending NSObject.

MultiLayout.h

    @interface MultiLayout  : UIView
    {
   // methods and properties
    }

    @end

    @interface SingleControl : NSObject
    {
   // methods and properties
    }

    @end

MultiLayout.m

@implementation SingleControl

//methods and variables declaration and property synthesization

@end

@implementation MultiLayout

//methods and variables declaration and property synthesization

@end

For getting the static value of SingleControl in MultiLayout . you have to call class method like:

MultiLayout.h

 @interface  MultiLayout : UIView
    {
   // methods and properties
    }

    @end

    @interface SingleControl : NSObject
    {
   // methods and properties
    }

   // add class method
   +(int)getValue;

    @end

MultiLayout.m

    @implementation SingleControl

    // add static value 
    static int values = 100;


    // implement method

   +(int)getValue{
    return values;
    }

    @end

    @implementation MultiLayout

    // call method to get value

     [SingleChoiceControl getValue];

    @end
KDeogharkar
  • 10,939
  • 7
  • 51
  • 95
  • Thanks a lot for your valuable reply,if I declare one static variable in MultiLayout,how to call that variable in another class? – user2439531 Jun 06 '13 at 09:55
  • using object of that multilayout class – KDeogharkar Jun 06 '13 at 09:56
  • what i am doing in my class that i am initializing the object of single choice class in my multi choice class and by using that object I am accessing methods and variables of single choice class – KDeogharkar Jun 06 '13 at 09:58
  • Can you please show me how to call that static variable in another class For eg.[[SingleControl MultiLayout]Register] – user2439531 Jun 06 '13 at 10:04
  • @user2439531 why have you asked this question again here which has nothing to do with the original question. You have already asked http://stackoverflow.com/questions/16955379/ios-how-to-declare-static-variable and gotten some good answers. – Popeye Jun 06 '13 at 10:23
0

If I understand your question correctly, you would do this in your interface file:

@interface Mime 

//properties and method declarations

@end

@interface UserRegistration : System.Web.UI.Page

@property (strong, nonatomic) Mime *mimeInstance;

@end

and then in the implementation file you implement both like so:

@implementation Mime 

//implementation

@end

@implementation UserRegistration

//implementation

@end