From 8c811ba9cacd3d36c69e1dfaaca6bf4ae886cdf8 Mon Sep 17 00:00:00 2001 From: Aparajita Fishman Date: Sun, 24 Mar 2013 19:40:04 -0400 Subject: [PATCH] Fixed: instantiating a cib with no owner would generate nil warning Previously, when a view-based table: - Had no delegate. - Used bindings for its data source, thus obviating the need for makeViewWithIdentifier:owner:. it would eventually call CPCib -instantiateCibWithOwner:topLevelObjects: with a nil owner (the nil table delegate). This method would try to construct a dictionary with the nil owner, which would generate a deprecation warning, and will in the future fail altogether. In Cocoa, this is exactly what happens, the owner is nil. And the documentation for -instantiateNibWithOwner:topLevelObjects: clearly states that the owner may be nil. This commit only adds the owner to the name table dictionary if the owner is non-nil. Since objectForKey: with a non-existent key returns nil, this is the same as storing nil for that key. --- AppKit/Cib/CPCib.j | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/AppKit/Cib/CPCib.j b/AppKit/Cib/CPCib.j index a56b77897..12c9611af 100644 --- a/AppKit/Cib/CPCib.j +++ b/AppKit/Cib/CPCib.j @@ -165,7 +165,14 @@ var CPCibObjectDataKey = @"CPCibObjectDataKey"; - (BOOL)instantiateCibWithOwner:(id)anOwner topLevelObjects:(CPArray)topLevelObjects { - return [self instantiateCibWithExternalNameTable:@{ CPCibOwner: anOwner, CPCibTopLevelObjects: topLevelObjects }]; + // anOwner can be nil, and we can't store nil in a dictionary. If we leave it out, + // anyone who asks for CPCibOwner will get nil back. + var nameTable = @{ CPCibTopLevelObjects: topLevelObjects }; + + if (anOwner) + [nameTable setObject:anOwner forKey:CPCibOwner]; + + return [self instantiateCibWithExternalNameTable:nameTable]; } @end