You can specify that NSMutableArray can contain only a specific type of object. For example, if I want to store only such objects:
@interface MyObject : NSObject { UInt8 value; }
To be able to use an instance variable as follows:
- (void)myMethod:(NSMutableArray *)myArray{ for (id myObject in myArray){ [self otherMethod:myObject.value]; } }
because i get this error:
request for member 'value' in something not a structure or union
thanks for the help
You get this error because for Objective-C, it myObjectis a non-type idthat does not support the property value. To make Objective-C aware that it always deals with myObjectthis loop, you have to say that the object myObjectis an instance myObject.
myObject
id
value
for (MyObject *myObject in myArray) {
, , value ivar , getter setter. , -value -setValue:, @property @synthesize, Objective-C .
-value
-setValue:
@property
@synthesize
, Java/#, .
Cocoa . , ( -, ).
Objective-C, , " , , , , , ". , , , , , .
, respondsToSelector:.
respondsToSelector:
, , . value - .
myObject.value. Objective-C .
myObject.value
Objective-C @protected, , - , - .
@protected
- (UInt8)value - (void)setValue:(UInt8)aValue .
- (UInt8)value
- (void)setValue:(UInt8)aValue
.
Objective-C . [myObject value] ( , -[value]). , .
[myObject value]
-[value]
- NSMutableArray, , .
NSMutableArray
NSMutableArray , . , [super addObject:xyz], .
[super addObject:xyz]
maybe you can use the protocol:
@protocol Person <NSObject> @end @interface Person : NSObject <Person> @end
for use:
NSArray<Person>* personArray;
Source: https://habr.com/ru/post/1743161/More articles:Can I use Catalyst to display images or graphs? - perlASP.NET user role management - c #Transaction isolation level required for secure identity escalation - sqlGoogle Maps: простое приложение не работает в IE - javascriptC # instance object - objectSet the Text and Value ComboBox property at design time - c #The width of the binding of the UI element to the width of another interface element - data-bindingJQuery tooltips on dynamically generated page - javascript.NET Memory Profiler Wanted - .netMulti-column latex problems - latexAll Articles