This is more like general question: Is there a way to assign a value like an if statement? I have a dictionary and I want to check if key exists and then assign. For example:
if((_attr.val = [self.dic objectForKey:@"name"]))
And i know that if key exist in _attr.val i will get object, if not i will get null. Great, but if statemant requires to_do_something after it, but in my case this is it – all what i want to do.
This is probably a silly question, but i’m having trouble with finding a solution.
I want to find something like ASSERT() known from c++.
The
ifmakes sense when you want to create a conditional path. In this case you just want to assign the value to_attr.val, still you should check if everything went was you expected. I would go with:If it really doesn’t matter the end result (either a value or nil) just go:
Either way, if you started this question with the
ifin mind it seems that you want to make some sort of check.With
NSAssert: