开发者

iOS: What's a safe way to create a temporary directory?

开发者 https://www.devze.com 2023-02-01 06:05 出处:网络
I read that NSTemporaryDirectory() returns a string for a temporary directory, but may also return nil.

I read that NSTemporaryDirectory() returns a string for a temporary directory, but may also return nil. Is this the case in iOS? Has anyone experience with NSTemporaryDirectory() returning nil? When does it happen?

If i have to be prepared that NSTemporaryDirectory() may return nil, it does not make sense for me to use it altogether. If i have to provide a fallback m开发者_JS百科echanism i can use this mechanism in the first place.

So what is a simple and safe way to create a temporary directory?


Being realistic, any situation that would lead NSTemporaryDirectory to return nil, would most likely mean that you wouldn't be able to save anything yourself anyway.

i.e.: It's likely to mean that the device is full, or that some form of corruption has occurred.

As such, I suspect that you should stick to using NSTemporaryDirectory (why re-invent the wheel after all) and treat it returning nil as effectively meaning you can't write to local storage.

0

精彩评论

暂无评论...
验证码 换一张
取 消