Add check for nil. Force use of subclass init methods

This commit is contained in:
Gregory John Casamento 2019-06-17 11:57:18 -04:00
parent 4edcc3f697
commit d20efecead
2 changed files with 20 additions and 23 deletions

View file

@ -161,7 +161,7 @@ static Class mutableSetClass;
return [self count]; return [self count];
} }
- (id) init - (instancetype) init
{ {
return [self initWithObjects: NULL count: 0]; return [self initWithObjects: NULL count: 0];
} }
@ -280,12 +280,19 @@ static Class mutableSetClass;
- (void) insertObject: (id)object atIndex: (NSUInteger)index - (void) insertObject: (id)object atIndex: (NSUInteger)index
{ {
GSIArrayItem item; GSIArrayItem item;
if([self containsObject: object] == NO) if(object == nil)
{ {
item.obj = object; NSWarnLog(@"Attempt to insert nil object");
GSIArrayInsertItem(&array, item, index); }
RETAIN(object); else
_version++; {
if([self containsObject: object] == NO)
{
item.obj = object;
GSIArrayInsertItem(&array, item, index);
RETAIN(object);
_version++;
}
} }
} }

View file

@ -506,12 +506,8 @@ static SEL rlSel;
- (instancetype) initWithObjects:(const id [])objects // required override. - (instancetype) initWithObjects:(const id [])objects // required override.
count:(NSUInteger)count count:(NSUInteger)count
{ {
self = [self init]; [self subclassResponsibility: _cmd];
if(self != nil) return nil;
{
// Need proper implementation in subclass since that is where data will be stored.
}
return self;
} }
- (instancetype) initWithOrderedSet:(NSOrderedSet *)aSet - (instancetype) initWithOrderedSet:(NSOrderedSet *)aSet
@ -622,12 +618,8 @@ static SEL rlSel;
- (instancetype) init - (instancetype) init
{ {
self = [super init]; [self subclassResponsibility: _cmd];
if(self == nil) return nil;
{
NSLog(@"NSOrderedSet not allocated.");
}
return self;
} }
- (NSUInteger) count // required override - (NSUInteger) count // required override
@ -1068,13 +1060,11 @@ static SEL rlSel;
// Key value coding support // Key value coding support
- (void) setValue: (id)value forKey: (NSString*)key - (void) setValue: (id)value forKey: (NSString*)key
{ {
NSUInteger i;
NSUInteger count = [self count];
volatile id object = nil; volatile id object = nil;
NSEnumerator *e = [self objectEnumerator];
for (i = 0; i < count; i++)
while((object = [e nextObject]) != nil)
{ {
object = [self objectAtIndex: i];
[object setValue: value [object setValue: value
forKey: key]; forKey: key];
} }