ayfer
ayfer

Reputation: 39

Property not found on object type of nested type object in Objective - C

@interface MyModel :NSObject

@property (strong, nonatomic) NSString *name;
@property (strong, nonatomic) NSMutableArray <MyModel> *items;
@property (strong, nonatomic) NSString *id;

@end

@interface SomeVC ()

@property (strong, nonatomic) NSObject *object;
@property (strong, nonatomic) NSMutableArray <MyModel> *items;


 _items = (NSMutableArray <MyModel> *)self.object;
 _items.items // !! COMPILE ERROR

and i am getting error propery not found on object type of (NSMutableArray <MyModel> *)

I work on a very long written classes so i writed some parts of codes.

I am trying to reach items object which has many MyModel object in it. Also inside of this MyModel objects there are a nested seconds items object MyModel type.

I am used to write in Swift. With type casting everything was easy. What is the good approach to type casting in Objective-C. How can give reference object to items and items.items be meaningful ?

Upvotes: 1

Views: 128

Answers (1)

skaak
skaak

Reputation: 3018

From your error I think you are missing an

#import "MyModel.h"

in the SomeVc.m class.

If you are in a hurry Objective-C is kind enough to allow you to do simply (and much more generally)

@property (strong, nonatomic) NSMutableArray * items;

with perhaps generating a warning. This just in terms of your type casting comment.

To specifically answer your question you really need a pointer to MyModel here, so change it to

@property (strong, nonatomic) NSMutableArray < MyModel * > * items;

Upvotes: 2

Related Questions