1

How to declare a Class property in objective-c?

Like this:

@property Class praise_usersClass;

it's right?

Wilson Yuan
  • 35
  • 1
  • 9
  • `@property (nonatomic, strong) ClassName *praise_usersClass;` – Tim007 Mar 31 '16 at 11:53
  • I guess it should be like that since you can't release a `Class` @property(unsafe_unretained,nomatomic) Class praise_usersClass; – Andrea Mar 31 '16 at 12:10
  • Do you mean class level properties, like static properties, which are attached to the class itself rather than an instance? If so, take a look at here: http://stackoverflow.com/questions/695980/how-do-i-declare-class-level-properties-in-objective-c – Dániel Nagy Mar 31 '16 at 12:47

1 Answers1

1

In Objective-C, Class is a pointer type and essentially also an object. So you can define a property as type Class just like any other object but you do not need to specify the pointer as it is part of the typedef definition.

Your example is fine:

@property Class praise_usersClass;

But FYI, note that you haven't specified any attributes so the defaults will apply:

@property (atomic,strong,readwrite) Class praise_usersClass;

For more information: Are classes structs or struct pointer

Community
  • 1
  • 1
Tim
  • 8,932
  • 4
  • 43
  • 64