I have a class Film, each of which stores a unique ID. In C#, Java etc I can define a static int currentID and each time i set the ID i can increase the currentID and the change occurs at the class level not object level. Can this be done in Objective C? I've found it very hard to find an answer for this.
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- back button text does not change
- iOS (objective-c) compression_decode_buffer() retu
- how to find the index position of the ARRAY Where
相关文章
- 现在使用swift开发ios应用好还是swift?
- TCC __TCCAccessRequest_block_invoke
- xcode 4 garbage collection removed?
- Unable to process app at this time due to a genera
- How can I add media attachments to my push notific
- didBeginContact:(SKPhysicsContact *)contact not in
- Custom Marker performance iOS, crash with result “
- Private static variables in php class
Here would be an option:
Note that this method will be the only method to access id, so you will have to update it somehow in this code.
Another possibility would be to have a little
NSNumber
subclass singleton.(Strictly speaking not an answer to the question, but in my experience likely to be useful when looking for class variables)
A class method can often play many of the roles a class variable would in other languages (e.g. changed configuration during tests):
Now, an object of class
MyCls
callsResource:changeSomething:
with the string@"Something general"
upon a call todoTheThing:
, but an object derived fromMySpecialCase
with the string@"Something specific"
.