Advertisement
Guest User

Untitled

a guest
Aug 30th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. MyClass(int a, String str){//constructor
  2. this.a = a;
  3. this.str = str;
  4.  
  5. // i am loking for similar way in obj-C as follows
  6. this.x = a*5;
  7. this.y = 'nothing';
  8. }
  9.  
  10. - (MyClass *)init {
  11. if (self = [super init]) {
  12. a = 4;
  13. str = @"test";
  14. }
  15. return self;
  16. }
  17.  
  18. @interface YourClass : NSObject {
  19. NSInteger a;
  20. NSInteger x;
  21. NSString *str;
  22. NSString *y;
  23. }
  24.  
  25. - (id)initWithInteger:(NSInteger)someInteger string:(NSString *)someString;
  26.  
  27. @end
  28.  
  29. - (id)initWithInteger:(NSInteger)someInteger string:(NSString *)someString {
  30. if (self = [super init]) {
  31. a = someInteger;
  32. str = [someString copy];
  33.  
  34. x = a * 5;
  35. y = [@"nothing" retain];
  36. }
  37.  
  38. return self;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement