objective c - How to send a message from an instance method to a object of another class -
i tried search reply (simple) question nil seems work well, books not specific (atleast books i've read), or i'm missing important, since i'm little bit confused i've decided seek here.
here's question:
say have classa contains 1 or many instance variables. have classb contains instance method modify classa variable (is possible right?) classes have not inheritance each other, both inherits nsobject
then want phone call method of classb on classa object on uiviewcontroller. believe need reference between classes i'm not sure on how set them create them works. imagine have paper contains writes or numbers (in case numbers) , class erase modify it's variable , erase numbers (for illustration subtracting).
here's code:
paper.h
@interface paper : nsobject @property (nonatomic) int numbers; @end
paper.m
#import "paper.h" @implementation paper @synthesize numbers; @end
and eraser.h
@interface eraser : nsobject -(void)erasemethod; @end
eraser.m
#import "eraser.h" @implementation eraser -(void)erasemethod { //here want create subtraction of ivar declared in paper } @end
and i'm trying phone call on uiviewcontroller so
[paperobject erasemethod];
i tried declaring @class in each files i've read somewhere won't help in way... hope clear question
ivars storage slots , private class when without specifying access conditions.you can utilize property purpose of accessing class. more info here
in order achive speak of,make method class method see here
#import "eraser.h" @implementation eraser +(void)erasemethod { //here want create subtraction of ivar declared in paper } @end
thus can accomplish method in vc.
objective-c class inheritance methods
No comments:
Post a Comment