I was initially thinking that the code below would return 0, my question, is there a function that I can use to only receive zero/positive results here?
NSUInteger pruneSize = 5 - 20; // Returns: -15
Currently I am just checking the result myself, but was wondering if I was missing something simpler.
NSUInteger pruneSize = 5 - 20;
if(pruneSize >= 0) {
// Do zero/positive Stuff ...
}
pruneSize >= 0is always true aspruneSizeis unsigned. You should get a warning here. You need to change the type toNSInteger, that is the signed integer. If you want to clip the lower value to zero for a signed int then you can do this: