In Objective-C why should I check if self = [super init] is not nil?

For example: [[NSData alloc] initWithContentsOfFile:@”this/path/doesn’t/exist/”]; [[NSImage alloc] initWithContentsOfFile:@”unsupportedFormat.sjt”]; [NSImage imageNamed:@”AnImageThatIsntInTheImageCache”]; … and so on. (Note: NSData might throw an exception if the file doesn’t exist). There are quite a few areas where returning nil is the expected behaviour when a problem occurs, and because of this it’s standard practice to check for nil pretty much … Read more

Why `null >= 0 && null

Your real question seem to be: Why: null >= 0; // true But: null == 0; // false What really happens is that the Greater-than-or-equal Operator (>=), performs type coercion (ToPrimitive), with a hint type of Number, actually all the relational operators have this behavior. null is treated in a special way by the Equals … Read more

Unique ways to use the null coalescing operator [closed]

Well, first of all, it’s much easier to chain than the standard ternary operator: string anybody = parm1 ?? localDefault ?? globalDefault; vs. string anyboby = (parm1 != null) ? parm1 : ((localDefault != null) ? localDefault : globalDefault); It also works well if a null-possible object isn’t a variable: string anybody = Parameters[“Name”] ?? … Read more

How do I get SUM function in MySQL to return ‘0’ if no values are found?

Use COALESCE to avoid that outcome. SELECT COALESCE(SUM(column),0) FROM table WHERE … To see it in action, please see this sql fiddle: http://www.sqlfiddle.com/#!2/d1542/3/0 More Information: Given three tables (one with all numbers, one with all nulls, and one with a mixture): SQL Fiddle MySQL 5.5.32 Schema Setup: CREATE TABLE foo ( id INT NOT NULL … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)