RAII in Objective-C pattern?
-
29-10-2019 - |
سؤال
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?
لا يوجد حل صحيح
لا تنتمي إلى StackOverflow