in Education by
I want to get variable value from an objective-c class, using reflection. company.h looks like @interface Company : NSObject { } @property (nonatomic, retain) NSString* phone; - (NSString*) getPropertyValueByName: (NSString*) paramName; company.m looks like @implementation Company @synthesize phone; - (NSString*) getPropertyValueByName: (NSString*) paramName { id me = self; value = [me objectForKey: paramName]; return value; } @end I am using this like: Company* comp = [Company new]; comp.phone = @"+30123456"; NSString* phone = comp.getPropertyValueByName(@"phone"); What I am getting is an exception: -[Company objectForKey:]: unrecognized selector sent to instance JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
There is a much easier way to do it by using Key-Value-Coding. There is already a way to get the value of a property by passing a string: -(id)valueForKey:(NSString *)keyName; You don't need to write your own methods for this.

Related questions

0 votes
    I have a UITableView of customers where a row/customer is selected. The user can then push another view ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 26, 2022 in Education by JackTerrance
0 votes
    I have a UITableView of customers where a row/customer is selected. The user can then push another view ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 25, 2022 in Education by JackTerrance
0 votes
    I have a UITableView of customers where a row/customer is selected. The user can then push another view ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 25, 2022 in Education by JackTerrance
0 votes
    I have a UITableView of customers where a row/customer is selected. The user can then push another view ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 24, 2022 in Education by JackTerrance
0 votes
    I'm working on an iPhone app with inApp payment: whenever the user pays a small sum, he receives ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    I'm working on an iPhone app with inApp payment: whenever the user pays a small sum, he receives ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    How do I call Objective-C code from Swift?...
asked Mar 9, 2021 in Technology by JackTerrance
0 votes
    This one has been bugging me for a while now. Is there a way I can stop Intellj IDEA from ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 24, 2022 in Education by JackTerrance
0 votes
    I'm using TensorFlow Alpha 2.0. I have TFRecords files I'm reading from, each one holding a short ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    I'm still trying to understand this piece of code that I found in a project I'm working on where ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 20, 2022 in Education by JackTerrance
0 votes
    I'm still trying to understand this piece of code that I found in a project I'm working on where ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    I wanted to create a gallery. It loads different images based on the category, that a user selects. I used to populate ... ; int imgCount = [galleryImages count]; for(int i=0;i...
asked Feb 16, 2022 in Education by JackTerrance
0 votes
    How we can layout subviews in a view in Objective-C?...
asked Nov 10, 2020 in Technology by JackTerrance
0 votes
    Can we create Dynamic Classes in Objective C? If Yes, Explain how to create with a valid use case?...
asked Nov 10, 2020 in Technology by JackTerrance
...