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];
}
- (id) init
- (instancetype) init
{
return [self initWithObjects: NULL count: 0];
}
@ -280,6 +280,12 @@ static Class mutableSetClass;
- (void) insertObject: (id)object atIndex: (NSUInteger)index
{
GSIArrayItem item;
if(object == nil)
{
NSWarnLog(@"Attempt to insert nil object");
}
else
{
if([self containsObject: object] == NO)
{
item.obj = object;
@ -287,6 +293,7 @@ static Class mutableSetClass;
RETAIN(object);
_version++;
}
}
}
- (void) _insertObject: (id)object atIndex: (NSUInteger)index

View file

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