Domanda

If we run the app on device with NSLogs then it may slow down the app to some extent.

Is NSAssert act in the same way as NSLog in the memory aspect?

Any comments or suggestions would be appreciated.

Thank you in advance.

È stato utile?

Soluzione

Maybe this will answer your question

It's important to note that as of Xcode 4.2, assertions are turned off by default for release builds, which is accomplished by defining the NS_BLOCK_ASSERTIONS macro. That is to say, when compiled for release, any calls to NSAssert & co. are effectively removed.

Source: http://nshipster.com/nsassertionhandler/

If you leave them enabled, then yes they come at a cost (obviously they need to be evaluated) and depending on what code you have them execute it differs. For simple nil comparisons it is negligible.

For further reference see: http://www.mikeash.com/pyblog/friday-qa-2013-05-03-proper-use-of-asserts.html

Specifically this passage

The runtime cost should be negligible, and if it's not, then you should redo your asserts to fix that.

Altri suggerimenti

In XCode, by default assertion are disabled in release, so they won't take any processing time. If you check in your build settings, NS_BLOCK_ASSERTIONS is set to 1 and looking at the NSAssert define in that case

#define NSAssert(condition, desc, ...) do {} while (0)

empty loop that will be removed at compilation time.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top