From 7bf2297125b330da80b7bab2137cad0e77ab98f6 Mon Sep 17 00:00:00 2001 From: Brian Donovan Date: Fri, 29 Oct 2010 14:02:53 -0700 Subject: [PATCH] -[CPArrayController setContent:] would interpret nil as [nil]. When initializing a CPArrayController with a value that is not an array setContent: would make it an array by replacing value with [value]. This is consistent with how Cocoa does it, but it should first check to make sure that the content is not nil. If it is, the sensible thing to do (and what Cocoa does) is to replace it with an empty array. This commit also includes a missing import to make CPArrayControllerTest run without error. --- AppKit/CPArrayController.j | 3 +++ AppKit/CPObjectController.j | 1 + Tests/AppKit/CPArrayControllerTest.j | 6 ++++++ 3 files changed, 10 insertions(+) diff --git a/AppKit/CPArrayController.j b/AppKit/CPArrayController.j index 42018c520..385819d62 100644 --- a/AppKit/CPArrayController.j +++ b/AppKit/CPArrayController.j @@ -150,6 +150,9 @@ - (void)setContent:(id)value { + if (value == nil) + value = []; + if (![value isKindOfClass:[CPArray class]]) value = [value]; diff --git a/AppKit/CPObjectController.j b/AppKit/CPObjectController.j index 02e3d961f..75c24d07f 100644 --- a/AppKit/CPObjectController.j +++ b/AppKit/CPObjectController.j @@ -1,5 +1,6 @@ @import +@import @import "CPController.j" diff --git a/Tests/AppKit/CPArrayControllerTest.j b/Tests/AppKit/CPArrayControllerTest.j index e921d0810..9ffb36647 100644 --- a/Tests/AppKit/CPArrayControllerTest.j +++ b/Tests/AppKit/CPArrayControllerTest.j @@ -27,6 +27,12 @@ [self assert:[_CPObservableArray class] equals:[[[self arrayController] arrangedObjects] class] message:"arranged objects should be observable"]; } +- (void)testInitWithoutContent +{ + _arrayController = [[CPArrayController alloc] init]; + [self assert:[] equals:[[self arrayController] contentArray]]; +} + - (void)testSetContent { otherContent = [@"5", @"6"];