문제

I'm writing an iOS app where my main 'UIViewController' creates a model (subclass of NSObject). When I am done using the model I want the model to write some data to file. Would it be appropriate/correct for me to do this file writing in the 'dealloc' method of my model? I want this file writing to always happen, even if a user exits the app.

도움이 되었습니까?

해결책

Please don't do this - the dealoc(see here) method should release memory(and writing to file/save is the opposite of this) and you can't control when it will be called(Maybe the user quits the app and dealoc wasn't called a single time). You can create a costum method which gets called when you are done with your model object. If you want to make sure that the data will be saved when the user quits the app write your save method in - (void)applicationDidEnterBackground:(UIApplication *)application

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top