Why should we always zero-out structs
by DalSeptember 15, 2015Development
I'm pretty sure that all professional C and C++ developers already know this, but it is not that common in Objective-C. Many OS X and iOS developers are not familiar with structs, or just forget how they work. Since many API's in OS X and iOS are still in C, it is very important that every developer working with those API's also knows how they work. One of the most used API's is definitely Core Graphics, which we use in almost every iOS or OS X application.
CGRect rect; rect.size = CGSizeMake (1024.0, 768.0); rect = CGRectOffset (100.0, 100.0, rect); view.frame = rect;NSUInteger count; // Count is 0This is an example of how easily Swift solves this problem, by forcing the developer to set all variables, before using the variable.
CGRect rect = CGRectZero; rect.size = CGSizeMake (1024.0, 768.0); rect = CGRectOffset (100.0, 100.0, rect); view.frame = rect;