RAII in Objective-C pattern?
-
29-10-2019 - |
Question
I find myself writing code like this to achieve exception safe code:
Container* container = [Container new];
@try {
while(someCondition) {
ElementType* value = [someObject createObjectFromStorage];
[container add:value]; // container retains object
[value release];
}
[_container release];
_container = [container retain];
} @finally {
[container release];
}
Is there some other, and more succinct pattern to follow in Objective-C?
No correct solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow