Questions tagged [nsassert]

NSAssert is an Objective-c Macro on Cocoa and Cocoa Touch which will generate an assertion if a given condition is false.

NSAssert is an Objective-c Macro on Cocoa and Cocoa Touch. It will evaluate a given condition. If the condition is false, then an exception will be thrown.

Visit Apple's Developer Documentation for more details.

See Also: , , , and NSAssert1

27 questions
157
votes
10 answers

What's the point of NSAssert, actually?

I have to ask this, because: The only thing I recognize is, that if the assertion fails, the app crashes. Is that the reason why to use NSAssert? Or what else is the benefit of it? And is it right to put an NSAssert just above any assumption I make…
HelloMoon
49
votes
5 answers

Weird error NSAssert

I can't figure out why I get use of undeclared identifier _cmd did you mean rcmd on the line where NSAssert is. #import int main (int argc, const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool…
foho
  • 779
  • 9
  • 20
8
votes
2 answers

What is NSAssert1?

I am developing an application on iOS. I see there is a macro called NSAssert1. What is it for? What are the differences in usage between NSLog and NSAssert1? Please guide me or suggest a tutorial where I can read about it.
Getsy
  • 4,887
  • 16
  • 78
  • 139
8
votes
2 answers

Why does not this NSAssert with stringWithFormat compile?

stringWithFormat should return a string, why does this statement not compile NSAssert(YES, [NSString stringWithFormat:@"%@",@"test if compiles"]); when NSAssert(YES, @"test if compiles"); compiles?
bogen
  • 9,954
  • 9
  • 50
  • 89
7
votes
2 answers

Why NSAssert1, etc instead of NSAssert?

I thought NSAssert couldn't use printf specifiers, but this: NSAssert(0, @"%@%@", @"foo", @"bar"); works just as you'd expect: *** Assertion failure in -[MyClass myMethod], /MyClass.m:84 *** Terminating app due to uncaught exception…
Steven Fisher
  • 44,462
  • 20
  • 138
  • 192
7
votes
0 answers

Xcode 8 doesn't print assertion message (for example when NSInternalInconsistencyException crash occurs)

Something is wrong with my project. It doesn't print assertion messages when debugging application and the app crashes. Normally it should display something like this: 2017-02-05 20:13:54.687 MyPlayground[29372:221950] *** Assertion failure in…
raven_raven
  • 343
  • 2
  • 6
  • 17
7
votes
4 answers

NSAssert vs NSCAssert

What is the difference between NSAssert and NSCAssert? When I explored their implementation they looked very similar and I couldn't find an answer to my question. I guess that it will also explain the difference between NSParameterAssert and…
KlimczakM
  • 12,576
  • 11
  • 64
  • 83
6
votes
3 answers

Asserting object class in Objective C

I often find myself asserting that an object "isKindOfClass" of some class in Objective-C. I do it like this: NSAssert([obj isKindOfClass:[AClass class]], @"%@ should be kind of class %@", obj, [[AClass class] description]); I'm wondering about the…
jbat100
  • 16,757
  • 4
  • 45
  • 70
4
votes
1 answer

NS_BLOCK_ASSERTIONS does not block an assertion in a static library

NS_BLOCK_ASSERTIONS does not block an assertion failure coming from a static library. How do we suppress assertion failure coming from a static library?
Boon
  • 40,656
  • 60
  • 209
  • 315
3
votes
1 answer

IOS equivalent of abort() for assertion failures

Is there a simple way of throwing the exception generated by an NSAssert when the condition is false? To draw a parallel of what I'm asking for: In C stdlib a failed assert results in a printf() and abort(). And in Java, a failed assert results in…
ɲeuroburɳ
  • 6,990
  • 3
  • 24
  • 22
3
votes
1 answer

How to confirm our code does not call NSAssert in iOS release binary

I'd like to disable NSAssert calls that occur in our codeline when building our release iOS binary, and I'd then like to confirm that they are disabled, because I'm super paranoid. How can I confirm they are disabled? To disable NSAssert calls in…
Goffredo
  • 541
  • 4
  • 14
2
votes
1 answer

How to exit the app after an error in user friendly manner?

I need to protect my code against possible errors. If they arise then there's no point to run the app further, so I need to bring to the user some message and then exit the app. So, I'm checking the conditions and then bringing alert: if…
Centurion
  • 14,106
  • 31
  • 105
  • 197
2
votes
3 answers

NSAssert doesn't work

I'm trying to use NSAssert in my code but it doesn't do a thing. In this piece of code, the assertion should fail but doesn't: MSLog(@"cross.obj = %@",[cross obj]); NSAssert([cross obj]!=nil,@"[cross obj] == nil"); The output of this…
Kristina
  • 15,859
  • 29
  • 111
  • 181
2
votes
0 answers

Xcode assertion failure messages do not show up in console log

I am using the latest Xcode, and have placed NSAssert() calls inside of my code. When one of the assertions fails, execution halts, and the console log states that an assertion error has occured, but the message in the NSAssert() call does not show…
dqhendricks
  • 19,030
  • 11
  • 50
  • 83
2
votes
2 answers

Why does NSAssert break in main instead of in the code that call the assertion

I set this NSAssert NSAssert(isStillLoadingArgument== [[self class] stillLoading],@"Hmm.... we think isStill Loading is false or true and yet stillLoading is true");; Here is the screenshot of where I ask this question: Then when assertion fail,…
user4951
  • 32,206
  • 53
  • 172
  • 282
1
2