From 22ff97b8129ecf035a6e87d4e69a17c2f329bfc5 Mon Sep 17 00:00:00 2001 From: Jun Tanaka Date: Wed, 9 Nov 2016 18:52:03 +0900 Subject: [PATCH] Disable -init in some classes to fix Xcode warnings --- ScreenLayout/SCLLayoutConstraint.h | 4 ++++ ScreenLayout/SCLLayoutConstraint.m | 22 +++++++++------------- ScreenLayout/SCLSessionMessage.h | 2 ++ ScreenLayout/SCLSessionMessage.m | 18 +++++++----------- 4 files changed, 22 insertions(+), 24 deletions(-) diff --git a/ScreenLayout/SCLLayoutConstraint.h b/ScreenLayout/SCLLayoutConstraint.h index 5899a8c..a03b8cd 100644 --- a/ScreenLayout/SCLLayoutConstraint.h +++ b/ScreenLayout/SCLLayoutConstraint.h @@ -19,6 +19,8 @@ NS_ASSUME_NONNULL_BEGIN */ @interface SCLLayoutConstraint : NSObject +- (instancetype)init NS_UNAVAILABLE; + /** @abstract Creates a SCLLayoutConstraint instance with the specified items. @param items An array constaining the SCLLayoutConstraintItem objects. @@ -48,6 +50,8 @@ NS_ASSUME_NONNULL_BEGIN */ @interface SCLLayoutConstraintItem : NSObject +- (instancetype)init NS_UNAVAILABLE; + /** @abstract Creates a SCLLayoutConstraintItem instance with the specified screen, anchor point and rotation. @param screen The screen which the receiver defines the geometry for. diff --git a/ScreenLayout/SCLLayoutConstraint.m b/ScreenLayout/SCLLayoutConstraint.m index e3b0306..5be92eb 100644 --- a/ScreenLayout/SCLLayoutConstraint.m +++ b/ScreenLayout/SCLLayoutConstraint.m @@ -90,14 +90,15 @@ - (instancetype)copyWithZone:(NSZone *)zone - (instancetype)initWithCoder:(NSCoder *)aDecoder { - self = [self init]; + NSArray *items = [aDecoder scl_decodeArrayOfObjectsOfClass:[SCLLayoutConstraintItem class] forSelector:@selector(items)]; + + self = [self initWithItems:items]; if (!self) { return nil; } _uuid = [aDecoder scl_decodeObjectOfClass:[NSUUID class] forSelector:@selector(uuid)]; - _items = [aDecoder scl_decodeArrayOfObjectsOfClass:[SCLLayoutConstraintItem class] forSelector:@selector(items)]; - + return self; } @@ -176,16 +177,11 @@ - (instancetype)copyWithZone:(NSZone *)zone - (instancetype)initWithCoder:(NSCoder *)aDecoder { - self = [self init]; - if (!self) { - return nil; - } - - _screen = [aDecoder scl_decodeObjectOfClass:[SCLScreen class] forSelector:@selector(screen)]; - _anchor = [aDecoder scl_decodeCGPointForSelector:@selector(anchor)]; - _rotation = [aDecoder scl_decodeCGFloatForSelector:@selector(rotation)]; - - return self; + SCLScreen *screen = [aDecoder scl_decodeObjectOfClass:[SCLScreen class] forSelector:@selector(screen)]; + CGPoint anchor = [aDecoder scl_decodeCGPointForSelector:@selector(anchor)]; + CGFloat rotation = [aDecoder scl_decodeCGFloatForSelector:@selector(rotation)]; + + return [self initWithScreen:screen anchor:anchor rotation:rotation]; } - (void)encodeWithCoder:(NSCoder *)aCoder diff --git a/ScreenLayout/SCLSessionMessage.h b/ScreenLayout/SCLSessionMessage.h index 8745c56..ec25708 100644 --- a/ScreenLayout/SCLSessionMessage.h +++ b/ScreenLayout/SCLSessionMessage.h @@ -12,6 +12,8 @@ NS_ASSUME_NONNULL_BEGIN @interface SCLSessionMessage : NSObject +- (instancetype)init NS_UNAVAILABLE; + - (instancetype)initWithName:(nonnull NSString *)name object:(nullable id)object; - (instancetype)initWithName:(nonnull NSString *)name object:(nullable id)object ofClasses:(nullable NSArray *)classes NS_DESIGNATED_INITIALIZER; diff --git a/ScreenLayout/SCLSessionMessage.m b/ScreenLayout/SCLSessionMessage.m index 63efc9b..0bdf634 100644 --- a/ScreenLayout/SCLSessionMessage.m +++ b/ScreenLayout/SCLSessionMessage.m @@ -112,26 +112,22 @@ - (instancetype)copyWithZone:(NSZone *)zone - (instancetype)initWithCoder:(NSCoder *)aDecoder { - self = [self init]; - if (!self) { - return nil; - } - - _name = [aDecoder scl_decodeObjectOfClass:[NSString class] forSelector:@selector(name)]; - _classNames = [aDecoder scl_decodeObjectOfClasses:@[[NSSet class], [NSString class]] forSelector:@selector(classNames)]; + NSString *name = [aDecoder scl_decodeObjectOfClass:[NSString class] forSelector:@selector(name)]; + NSSet *classNames = [aDecoder scl_decodeObjectOfClasses:@[[NSSet class], [NSString class]] forSelector:@selector(classNames)]; + id object = nil; NSMutableArray *classes = [[NSMutableArray alloc] init]; - [_classNames enumerateObjectsUsingBlock:^(NSString *className, BOOL *stop) { + [classNames enumerateObjectsUsingBlock:^(NSString *className, BOOL *stop) { Class class = NSClassFromString(className); if (class) { [classes addObject:class]; } }]; if (classes.count > 0) { - _object = [aDecoder scl_decodeObjectOfClasses:classes forSelector:@selector(object)]; + object = [aDecoder scl_decodeObjectOfClasses:classes forSelector:@selector(object)]; } - - return self; + + return [self initWithName:name object:object ofClasses:classes]; } - (void)encodeWithCoder:(NSCoder *)aCoder