From 5543c094e93f9da80136065c0b16e7ea37bda72a Mon Sep 17 00:00:00 2001 From: Viktor Lesyk Date: Mon, 27 Feb 2017 15:03:10 +0100 Subject: [PATCH] Update: Obj-C code --- Lumberjack/DDASLLogger.m | 4 +- Lumberjack/DDAbstractDatabaseLogger.m | 2 +- Lumberjack/DDFileLogger.h | 30 ++-- Lumberjack/DDFileLogger.m | 128 +++++++++--------- Lumberjack/DDLog.h | 24 ++-- Lumberjack/DDLog.m | 16 +-- Lumberjack/DDTTYLogger.m | 28 ++-- .../Extensions/ContextFilterLogFormatter.h | 8 +- .../Extensions/ContextFilterLogFormatter.m | 10 +- .../Extensions/DispatchQueueLogFormatter.h | 2 +- .../Extensions/DispatchQueueLogFormatter.m | 30 ++-- .../HueQuickStartApp-iOS/PHAppDelegate.m | 12 +- .../PHControlLightsViewController.m | 12 +- .../LoadingView/PHLoadingViewController.m | 2 +- .../PHBridgePushLinkViewController.h | 2 +- .../PHBridgePushLinkViewController.m | 12 +- .../PHBridgeSelectionViewController.h | 2 +- .../PHBridgeSelectionViewController.m | 10 +- 18 files changed, 166 insertions(+), 168 deletions(-) diff --git a/Lumberjack/DDASLLogger.m b/Lumberjack/DDASLLogger.m index 0c35f2f..516fa9b 100755 --- a/Lumberjack/DDASLLogger.m +++ b/Lumberjack/DDASLLogger.m @@ -45,7 +45,7 @@ + (DDASLLogger *)sharedInstance return sharedInstance; } -- (id)init +- (instancetype)init { if (sharedInstance != nil) { @@ -73,7 +73,7 @@ - (void)logMessage:(DDLogMessage *)logMessage if (logMsg) { - const char *msg = [logMsg UTF8String]; + const char *msg = logMsg.UTF8String; int aslLogLevel; switch (logMessage->logFlag) diff --git a/Lumberjack/DDAbstractDatabaseLogger.m b/Lumberjack/DDAbstractDatabaseLogger.m index c7366a6..0ed5aec 100755 --- a/Lumberjack/DDAbstractDatabaseLogger.m +++ b/Lumberjack/DDAbstractDatabaseLogger.m @@ -24,7 +24,7 @@ - (void)destroyDeleteTimer; @implementation DDAbstractDatabaseLogger -- (id)init +- (instancetype)init { if ((self = [super init])) { diff --git a/Lumberjack/DDFileLogger.h b/Lumberjack/DDFileLogger.h index 5af6376..8eee2a0 100755 --- a/Lumberjack/DDFileLogger.h +++ b/Lumberjack/DDFileLogger.h @@ -73,19 +73,19 @@ // Public methods -- (NSString *)logsDirectory; +@property (NS_NONATOMIC_IOSONLY, readonly, copy) NSString *logsDirectory; -- (NSArray *)unsortedLogFilePaths; -- (NSArray *)unsortedLogFileNames; -- (NSArray *)unsortedLogFileInfos; +@property (NS_NONATOMIC_IOSONLY, readonly, copy) NSArray *unsortedLogFilePaths; +@property (NS_NONATOMIC_IOSONLY, readonly, copy) NSArray *unsortedLogFileNames; +@property (NS_NONATOMIC_IOSONLY, readonly, copy) NSArray *unsortedLogFileInfos; -- (NSArray *)sortedLogFilePaths; -- (NSArray *)sortedLogFileNames; -- (NSArray *)sortedLogFileInfos; +@property (NS_NONATOMIC_IOSONLY, readonly, copy) NSArray *sortedLogFilePaths; +@property (NS_NONATOMIC_IOSONLY, readonly, copy) NSArray *sortedLogFileNames; +@property (NS_NONATOMIC_IOSONLY, readonly, copy) NSArray *sortedLogFileInfos; // Private methods (only to be used by DDFileLogger) -- (NSString *)createNewLogFile; +@property (NS_NONATOMIC_IOSONLY, readonly, copy) NSString *createNewLogFile; @optional @@ -119,8 +119,8 @@ NSString *_logsDirectory; } -- (id)init; -- (id)initWithLogsDirectory:(NSString *)logsDirectory; +- (instancetype)init; +- (instancetype)initWithLogsDirectory:(NSString *)logsDirectory NS_DESIGNATED_INITIALIZER; /* Inherited from DDLogFileManager protocol: @@ -159,8 +159,8 @@ NSDateFormatter *dateFormatter; } -- (id)init; -- (id)initWithDateFormatter:(NSDateFormatter *)dateFormatter; +- (instancetype)init; +- (instancetype)initWithDateFormatter:(NSDateFormatter *)dateFormatter NS_DESIGNATED_INITIALIZER; @end @@ -181,8 +181,8 @@ NSTimeInterval rollingFrequency; } -- (id)init; -- (id)initWithLogFileManager:(id )logFileManager; +- (instancetype)init; +- (instancetype)initWithLogFileManager:(id )logFileManager NS_DESIGNATED_INITIALIZER; /** * Log File Rolling: @@ -285,7 +285,7 @@ + (id)logFileWithPath:(NSString *)filePath; -- (id)initWithFilePath:(NSString *)filePath; +- (instancetype)initWithFilePath:(NSString *)filePath NS_DESIGNATED_INITIALIZER; - (void)reset; - (void)renameFile:(NSString *)newFileName; diff --git a/Lumberjack/DDFileLogger.m b/Lumberjack/DDFileLogger.m index afe7cc1..1acdce5 100755 --- a/Lumberjack/DDFileLogger.m +++ b/Lumberjack/DDFileLogger.m @@ -56,12 +56,12 @@ @implementation DDLogFileManagerDefault @synthesize maximumNumberOfLogFiles; -- (id)init +- (instancetype)init { return [self initWithLogsDirectory:nil]; } -- (id)initWithLogsDirectory:(NSString *)aLogsDirectory +- (instancetype)initWithLogsDirectory:(NSString *)aLogsDirectory { if ((self = [super init])) { @@ -96,8 +96,8 @@ - (void)observeValueForKeyPath:(NSString *)keyPath change:(NSDictionary *)change context:(void *)context { - NSNumber *old = [change objectForKey:NSKeyValueChangeOldKey]; - NSNumber *new = [change objectForKey:NSKeyValueChangeNewKey]; + NSNumber *old = change[NSKeyValueChangeOldKey]; + NSNumber *new = change[NSKeyValueChangeNewKey]; if ([old isEqual:new]) { @@ -141,12 +141,12 @@ - (void)deleteOldLogFiles // In most cases, the first file is likely the log file that is currently being written to. // So in most cases, we do not want to consider this file for deletion. - NSUInteger count = [sortedLogFileInfos count]; + NSUInteger count = sortedLogFileInfos.count; BOOL excludeFirstFile = NO; if (count > 0) { - DDLogFileInfo *logFileInfo = [sortedLogFileInfos objectAtIndex:0]; + DDLogFileInfo *logFileInfo = sortedLogFileInfos[0]; if (!logFileInfo.isArchived) { @@ -168,7 +168,7 @@ - (void)deleteOldLogFiles NSUInteger i; for (i = maxNumLogFiles; i < count; i++) { - DDLogFileInfo *logFileInfo = [sortedArchivedLogFileInfos objectAtIndex:i]; + DDLogFileInfo *logFileInfo = sortedArchivedLogFileInfos[i]; NSLogInfo(@"DDLogFileManagerDefault: Deleting file: %@", logFileInfo.fileName); @@ -188,7 +188,7 @@ - (NSString *)defaultLogsDirectory { #if TARGET_OS_IPHONE NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); - NSString *baseDir = ([paths count] > 0) ? [paths objectAtIndex:0] : nil; + NSString *baseDir = (paths.count > 0) ? paths[0] : nil; NSString *logsDirectory = [baseDir stringByAppendingPathComponent:@"Logs"]; #else @@ -228,7 +228,7 @@ - (BOOL)isLogFile:(NSString *)fileName BOOL hasProperPrefix = [fileName hasPrefix:@"log-"]; - BOOL hasProperLength = [fileName length] >= 10; + BOOL hasProperLength = fileName.length >= 10; if (hasProperPrefix && hasProperLength) @@ -238,7 +238,7 @@ - (BOOL)isLogFile:(NSString *)fileName NSString *hex = [fileName substringWithRange:NSMakeRange(4, 6)]; NSString *nohex = [hex stringByTrimmingCharactersInSet:hexSet]; - if ([nohex length] == 0) + if (nohex.length == 0) { return YES; } @@ -256,7 +256,7 @@ - (NSArray *)unsortedLogFilePaths NSString *logsDirectory = [self logsDirectory]; NSArray *fileNames = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:logsDirectory error:nil]; - NSMutableArray *unsortedLogFilePaths = [NSMutableArray arrayWithCapacity:[fileNames count]]; + NSMutableArray *unsortedLogFilePaths = [NSMutableArray arrayWithCapacity:fileNames.count]; for (NSString *fileName in fileNames) { @@ -281,11 +281,11 @@ - (NSArray *)unsortedLogFileNames { NSArray *unsortedLogFilePaths = [self unsortedLogFilePaths]; - NSMutableArray *unsortedLogFileNames = [NSMutableArray arrayWithCapacity:[unsortedLogFilePaths count]]; + NSMutableArray *unsortedLogFileNames = [NSMutableArray arrayWithCapacity:unsortedLogFilePaths.count]; for (NSString *filePath in unsortedLogFilePaths) { - [unsortedLogFileNames addObject:[filePath lastPathComponent]]; + [unsortedLogFileNames addObject:filePath.lastPathComponent]; } return unsortedLogFileNames; @@ -300,7 +300,7 @@ - (NSArray *)unsortedLogFileInfos { NSArray *unsortedLogFilePaths = [self unsortedLogFilePaths]; - NSMutableArray *unsortedLogFileInfos = [NSMutableArray arrayWithCapacity:[unsortedLogFilePaths count]]; + NSMutableArray *unsortedLogFileInfos = [NSMutableArray arrayWithCapacity:unsortedLogFilePaths.count]; for (NSString *filePath in unsortedLogFilePaths) { @@ -321,11 +321,11 @@ - (NSArray *)sortedLogFilePaths { NSArray *sortedLogFileInfos = [self sortedLogFileInfos]; - NSMutableArray *sortedLogFilePaths = [NSMutableArray arrayWithCapacity:[sortedLogFileInfos count]]; + NSMutableArray *sortedLogFilePaths = [NSMutableArray arrayWithCapacity:sortedLogFileInfos.count]; for (DDLogFileInfo *logFileInfo in sortedLogFileInfos) { - [sortedLogFilePaths addObject:[logFileInfo filePath]]; + [sortedLogFilePaths addObject:logFileInfo.filePath]; } return sortedLogFilePaths; @@ -340,11 +340,11 @@ - (NSArray *)sortedLogFileNames { NSArray *sortedLogFileInfos = [self sortedLogFileInfos]; - NSMutableArray *sortedLogFileNames = [NSMutableArray arrayWithCapacity:[sortedLogFileInfos count]]; + NSMutableArray *sortedLogFileNames = [NSMutableArray arrayWithCapacity:sortedLogFileInfos.count]; for (DDLogFileInfo *logFileInfo in sortedLogFileInfos) { - [sortedLogFileNames addObject:[logFileInfo fileName]]; + [sortedLogFileNames addObject:logFileInfo.fileName]; } return sortedLogFileNames; @@ -418,12 +418,12 @@ - (NSString *)createNewLogFile @implementation DDLogFileFormatterDefault -- (id)init +- (instancetype)init { return [self initWithDateFormatter:nil]; } -- (id)initWithDateFormatter:(NSDateFormatter *)aDateFormatter +- (instancetype)initWithDateFormatter:(NSDateFormatter *)aDateFormatter { if ((self = [super init])) { @@ -434,8 +434,8 @@ - (id)initWithDateFormatter:(NSDateFormatter *)aDateFormatter else { dateFormatter = [[NSDateFormatter alloc] init]; - [dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4]; // 10.4+ style - [dateFormatter setDateFormat:@"yyyy/MM/dd HH:mm:ss:SSS"]; + dateFormatter.formatterBehavior = NSDateFormatterBehavior10_4; // 10.4+ style + dateFormatter.dateFormat = @"yyyy/MM/dd HH:mm:ss:SSS"; } } return self; @@ -456,14 +456,14 @@ - (NSString *)formatLogMessage:(DDLogMessage *)logMessage @implementation DDFileLogger -- (id)init +- (instancetype)init { DDLogFileManagerDefault *defaultLogFileManager = [[DDLogFileManagerDefault alloc] init]; return [self initWithLogFileManager:defaultLogFileManager]; } -- (id)initWithLogFileManager:(id )aLogFileManager +- (instancetype)initWithLogFileManager:(id )aLogFileManager { if ((self = [super init])) { @@ -629,9 +629,9 @@ - (void)scheduleTimerToRollLogFileDueToAge return; } - NSDate *logFileCreationDate = [currentLogFileInfo creationDate]; + NSDate *logFileCreationDate = currentLogFileInfo.creationDate; - NSTimeInterval ti = [logFileCreationDate timeIntervalSinceReferenceDate]; + NSTimeInterval ti = logFileCreationDate.timeIntervalSinceReferenceDate; ti += rollingFrequency; NSDate *logFileRollingDate = [NSDate dateWithTimeIntervalSinceReferenceDate:ti]; @@ -656,7 +656,7 @@ - (void)scheduleTimerToRollLogFileDueToAge }); #endif - uint64_t delay = (uint64_t)([logFileRollingDate timeIntervalSinceNow] * NSEC_PER_SEC); + uint64_t delay = (uint64_t)(logFileRollingDate.timeIntervalSinceNow * NSEC_PER_SEC); dispatch_time_t fireTime = dispatch_time(DISPATCH_TIME_NOW, delay); dispatch_source_set_timer(rollingTimer, fireTime, DISPATCH_TIME_FOREVER, 1.0); @@ -742,7 +742,7 @@ - (void)maybeRollLogFileDueToSize if (maximumFileSize > 0) { - unsigned long long fileSize = [currentLogFileHandle offsetInFile]; + unsigned long long fileSize = currentLogFileHandle.offsetInFile; if (fileSize >= maximumFileSize) { @@ -770,9 +770,9 @@ - (DDLogFileInfo *)currentLogFileInfo { NSArray *sortedLogFileInfos = [logFileManager sortedLogFileInfos]; - if ([sortedLogFileInfos count] > 0) + if (sortedLogFileInfos.count > 0) { - DDLogFileInfo *mostRecentLogFileInfo = [sortedLogFileInfos objectAtIndex:0]; + DDLogFileInfo *mostRecentLogFileInfo = sortedLogFileInfos[0]; BOOL useExistingLogFile = YES; BOOL shouldArchiveMostRecent = NO; @@ -828,7 +828,7 @@ - (NSFileHandle *)currentLogFileHandle { if (currentLogFileHandle == nil) { - NSString *logFilePath = [[self currentLogFileInfo] filePath]; + NSString *logFilePath = [self currentLogFileInfo].filePath; currentLogFileHandle = [NSFileHandle fileHandleForWritingAtPath:logFilePath]; [currentLogFileHandle seekToEndOfFile]; @@ -915,7 +915,7 @@ + (id)logFileWithPath:(NSString *)aFilePath return [[DDLogFileInfo alloc] initWithFilePath:aFilePath]; } -- (id)initWithFilePath:(NSString *)aFilePath +- (instancetype)initWithFilePath:(NSString *)aFilePath { if ((self = [super init])) { @@ -941,7 +941,7 @@ - (NSString *)fileName { if (fileName == nil) { - fileName = [filePath lastPathComponent]; + fileName = filePath.lastPathComponent; } return fileName; } @@ -950,7 +950,7 @@ - (NSDate *)modificationDate { if (modificationDate == nil) { - modificationDate = [[self fileAttributes] objectForKey:NSFileModificationDate]; + modificationDate = self.fileAttributes[NSFileModificationDate]; } return modificationDate; @@ -963,7 +963,7 @@ - (NSDate *)creationDate #if TARGET_OS_IPHONE - const char *path = [filePath UTF8String]; + const char *path = filePath.UTF8String; struct attrlist attrList; memset(&attrList, 0, sizeof(attrList)); @@ -1004,7 +1004,7 @@ - (unsigned long long)fileSize { if (fileSize == 0) { - fileSize = [[[self fileAttributes] objectForKey:NSFileSize] unsignedLongLongValue]; + fileSize = [self.fileAttributes[NSFileSize] unsignedLongLongValue]; } return fileSize; @@ -1012,19 +1012,19 @@ - (unsigned long long)fileSize - (NSTimeInterval)age { - return [[self creationDate] timeIntervalSinceNow] * -1.0; + return self.creationDate.timeIntervalSinceNow * -1.0; } - (NSString *)description { - return [@{@"filePath": self.filePath, + return (@{@"filePath": self.filePath, @"fileName": self.fileName, @"fileAttributes": self.fileAttributes, @"creationDate": self.creationDate, @"modificationDate": self.modificationDate, @"fileSize": @(self.fileSize), @"age": @(self.age), - @"isArchived": @(self.isArchived)} description]; + @"isArchived": @(self.isArchived)}).description; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1090,9 +1090,9 @@ - (void)renameFile:(NSString *)newFileName // This method is only used on the iPhone simulator, where normal extended attributes are broken. // See full explanation in the header file. - if (![newFileName isEqualToString:[self fileName]]) + if (![newFileName isEqualToString:self.fileName]) { - NSString *fileDir = [filePath stringByDeletingLastPathComponent]; + NSString *fileDir = filePath.stringByDeletingLastPathComponent; NSString *newFilePath = [fileDir stringByAppendingPathComponent:newFileName]; @@ -1135,17 +1135,17 @@ - (BOOL)hasExtensionAttributeWithName:(NSString *)attrName // // So we want to search for the attrName in the components (ignoring the first and last array indexes). - NSArray *components = [[self fileName] componentsSeparatedByString:@"."]; + NSArray *components = [self.fileName componentsSeparatedByString:@"."]; // Watch out for file names without an extension - NSUInteger count = [components count]; + NSUInteger count = components.count; NSUInteger max = (count >= 2) ? count-1 : count; NSUInteger i; for (i = 1; i < max; i++) { - NSString *attr = [components objectAtIndex:i]; + NSString *attr = components[i]; if ([attrName isEqualToString:attr]) { @@ -1161,23 +1161,23 @@ - (void)addExtensionAttributeWithName:(NSString *)attrName // This method is only used on the iPhone simulator, where normal extended attributes are broken. // See full explanation in the header file. - if ([attrName length] == 0) return; + if (attrName.length == 0) return; // Example: // attrName = "archived" // // "log-ABC123.txt" -> "log-ABC123.archived.txt" - NSArray *components = [[self fileName] componentsSeparatedByString:@"."]; + NSArray *components = [self.fileName componentsSeparatedByString:@"."]; - NSUInteger count = [components count]; + NSUInteger count = components.count; - NSUInteger estimatedNewLength = [[self fileName] length] + [attrName length] + 1; + NSUInteger estimatedNewLength = self.fileName.length + attrName.length + 1; NSMutableString *newFileName = [NSMutableString stringWithCapacity:estimatedNewLength]; if (count > 0) { - [newFileName appendString:[components objectAtIndex:0]]; + [newFileName appendString:components[0]]; } NSString *lastExt = @""; @@ -1185,8 +1185,8 @@ - (void)addExtensionAttributeWithName:(NSString *)attrName NSUInteger i; for (i = 1; i < count; i++) { - NSString *attr = [components objectAtIndex:i]; - if ([attr length] == 0) + NSString *attr = components[i]; + if (attr.length == 0) { continue; } @@ -1197,7 +1197,7 @@ - (void)addExtensionAttributeWithName:(NSString *)attrName return; } - if ([lastExt length] > 0) + if (lastExt.length > 0) { [newFileName appendFormat:@".%@", lastExt]; } @@ -1207,7 +1207,7 @@ - (void)addExtensionAttributeWithName:(NSString *)attrName [newFileName appendFormat:@".%@", attrName]; - if ([lastExt length] > 0) + if (lastExt.length > 0) { [newFileName appendFormat:@".%@", lastExt]; } @@ -1220,23 +1220,23 @@ - (void)removeExtensionAttributeWithName:(NSString *)attrName // This method is only used on the iPhone simulator, where normal extended attributes are broken. // See full explanation in the header file. - if ([attrName length] == 0) return; + if (attrName.length == 0) return; // Example: // attrName = "archived" // // "log-ABC123.txt" -> "log-ABC123.archived.txt" - NSArray *components = [[self fileName] componentsSeparatedByString:@"."]; + NSArray *components = [self.fileName componentsSeparatedByString:@"."]; - NSUInteger count = [components count]; + NSUInteger count = components.count; - NSUInteger estimatedNewLength = [[self fileName] length]; + NSUInteger estimatedNewLength = self.fileName.length; NSMutableString *newFileName = [NSMutableString stringWithCapacity:estimatedNewLength]; if (count > 0) { - [newFileName appendString:[components objectAtIndex:0]]; + [newFileName appendString:components[0]]; } BOOL found = NO; @@ -1244,7 +1244,7 @@ - (void)removeExtensionAttributeWithName:(NSString *)attrName NSUInteger i; for (i = 1; i < count; i++) { - NSString *attr = [components objectAtIndex:i]; + NSString *attr = components[i]; if ([attrName isEqualToString:attr]) { @@ -1312,7 +1312,7 @@ - (BOOL)isEqual:(id)object { DDLogFileInfo *another = (DDLogFileInfo *)object; - return [filePath isEqualToString:[another filePath]]; + return [filePath isEqualToString:another.filePath]; } return NO; @@ -1320,8 +1320,8 @@ - (BOOL)isEqual:(id)object - (NSComparisonResult)reverseCompareByCreationDate:(DDLogFileInfo *)another { - NSDate *us = [self creationDate]; - NSDate *them = [another creationDate]; + NSDate *us = self.creationDate; + NSDate *them = another.creationDate; NSComparisonResult result = [us compare:them]; @@ -1336,8 +1336,8 @@ - (NSComparisonResult)reverseCompareByCreationDate:(DDLogFileInfo *)another - (NSComparisonResult)reverseCompareByModificationDate:(DDLogFileInfo *)another { - NSDate *us = [self modificationDate]; - NSDate *them = [another modificationDate]; + NSDate *us = self.modificationDate; + NSDate *them = another.modificationDate; NSComparisonResult result = [us compare:them]; diff --git a/Lumberjack/DDLog.h b/Lumberjack/DDLog.h index b23337a..06cf6c9 100755 --- a/Lumberjack/DDLog.h +++ b/Lumberjack/DDLog.h @@ -361,8 +361,7 @@ NSString *DDExtractFileNameWithoutExtension(const char *filePath, BOOL copy); * If no formatter is set, the logger simply logs the message as it is given in logMessage, * or it may use its own built in formatting style. **/ -- (id )logFormatter; -- (void)setLogFormatter:(id )formatter; +@property (NS_NONATOMIC_IOSONLY, strong) id logFormatter; @optional @@ -397,7 +396,7 @@ NSString *DDExtractFileNameWithoutExtension(const char *filePath, BOOL copy); * Thus, a dedicated dispatch queue is used for each logger. * Logger implementations may optionally choose to provide their own dispatch queue. **/ -- (dispatch_queue_t)loggerQueue; +@property (NS_NONATOMIC_IOSONLY, readonly, strong) dispatch_queue_t loggerQueue; /** * If the logger implementation does not choose to provide its own queue, @@ -405,7 +404,7 @@ NSString *DDExtractFileNameWithoutExtension(const char *filePath, BOOL copy); * The created queue will receive its name from this method. * This may be helpful for debugging or profiling reasons. **/ -- (NSString *)loggerName; +@property (NS_NONATOMIC_IOSONLY, readonly, copy) NSString *loggerName; @end @@ -534,7 +533,7 @@ typedef int DDLogMessageOptions; * However, if you need them to be copied you may use the options parameter to specify this. * Options is a bitmask which supports DDLogMessageCopyFile and DDLogMessageCopyFunction. **/ -- (id)initWithLogMsg:(NSString *)logMsg +- (instancetype)initWithLogMsg:(NSString *)logMsg level:(int)logLevel flag:(int)logFlag context:(int)logContext @@ -542,24 +541,24 @@ typedef int DDLogMessageOptions; function:(const char *)function line:(int)line tag:(id)tag - options:(DDLogMessageOptions)optionsMask; + options:(DDLogMessageOptions)optionsMask NS_DESIGNATED_INITIALIZER; /** * Returns the threadID as it appears in NSLog. * That is, it is a hexadecimal value which is calculated from the machThreadID. **/ -- (NSString *)threadID; +@property (NS_NONATOMIC_IOSONLY, readonly, copy) NSString *threadID; /** * Convenience property to get just the file name, as the file variable is generally the full file path. * This method does not include the file extension, which is generally unwanted for logging purposes. **/ -- (NSString *)fileName; +@property (NS_NONATOMIC_IOSONLY, readonly, copy) NSString *fileName; /** * Returns the function variable in NSString form. **/ -- (NSString *)methodName; +@property (NS_NONATOMIC_IOSONLY, readonly, copy) NSString *methodName; @end @@ -591,11 +590,10 @@ typedef int DDLogMessageOptions; dispatch_queue_t loggerQueue; } -- (id )logFormatter; -- (void)setLogFormatter:(id )formatter; +@property (NS_NONATOMIC_IOSONLY, strong) id logFormatter; // For thread-safety assertions -- (BOOL)isOnGlobalLoggingQueue; -- (BOOL)isOnInternalLoggerQueue; +@property (NS_NONATOMIC_IOSONLY, getter=isOnGlobalLoggingQueue, readonly) BOOL onGlobalLoggingQueue; +@property (NS_NONATOMIC_IOSONLY, getter=isOnInternalLoggerQueue, readonly) BOOL onInternalLoggerQueue; @end diff --git a/Lumberjack/DDLog.m b/Lumberjack/DDLog.m index 287fc08..9fcd5e0 100755 --- a/Lumberjack/DDLog.m +++ b/Lumberjack/DDLog.m @@ -455,7 +455,7 @@ + (NSArray *)registeredClasses + (NSArray *)registeredClassNames { NSArray *registeredClasses = [self registeredClasses]; - NSMutableArray *result = [NSMutableArray arrayWithCapacity:[registeredClasses count]]; + NSMutableArray *result = [NSMutableArray arrayWithCapacity:registeredClasses.count]; for (Class class in registeredClasses) { @@ -526,7 +526,7 @@ + (void)lt_addLogger:(id )logger const char *loggerQueueName = NULL; if ([logger respondsToSelector:@selector(loggerName)]) { - loggerQueueName = [[logger loggerName] UTF8String]; + loggerQueueName = [logger loggerName].UTF8String; } loggerQueue = dispatch_queue_create(loggerQueueName, NULL); @@ -773,7 +773,7 @@ + (void)lt_flush @implementation DDLoggerNode -- (id)initWithLogger:(id )aLogger loggerQueue:(dispatch_queue_t)aLoggerQueue +- (instancetype)initWithLogger:(id )aLogger loggerQueue:(dispatch_queue_t)aLoggerQueue { if ((self = [super init])) { @@ -822,7 +822,7 @@ @implementation DDLogMessage return result; } -- (id)initWithLogMsg:(NSString *)msg +- (instancetype)initWithLogMsg:(NSString *)msg level:(int)level flag:(int)flag context:(int)context @@ -875,7 +875,7 @@ - (id)initWithLogMsg:(NSString *)msg queueLabel = dd_str_copy(dispatch_queue_get_label(currentQueue)); - threadName = [[NSThread currentThread] name]; + threadName = [NSThread currentThread].name; } return self; } @@ -895,7 +895,7 @@ - (NSString *)methodName if (function == NULL) return nil; else - return [[NSString alloc] initWithUTF8String:function]; + return @(function); } - (void)dealloc @@ -918,14 +918,14 @@ - (void)dealloc @implementation DDAbstractLogger -- (id)init +- (instancetype)init { if ((self = [super init])) { const char *loggerQueueName = NULL; if ([self respondsToSelector:@selector(loggerName)]) { - loggerQueueName = [[self loggerName] UTF8String]; + loggerQueueName = [self loggerName].UTF8String; } loggerQueue = dispatch_queue_create(loggerQueueName, NULL); diff --git a/Lumberjack/DDTTYLogger.m b/Lumberjack/DDTTYLogger.m index 8b4c097..c048785 100755 --- a/Lumberjack/DDTTYLogger.m +++ b/Lumberjack/DDTTYLogger.m @@ -115,7 +115,7 @@ @interface DDTTYLoggerColorProfile : NSObject { size_t resetCodeLen; } -- (id)initWithForegroundColor:(OSColor *)fgColor backgroundColor:(OSColor *)bgColor flag:(int)mask context:(int)ctxt; +- (instancetype)initWithForegroundColor:(OSColor *)fgColor backgroundColor:(OSColor *)bgColor flag:(int)mask context:(int)ctxt NS_DESIGNATED_INITIALIZER; @end @@ -687,7 +687,7 @@ + (void)getRed:(CGFloat *)rPtr green:(CGFloat *)gPtr blue:(CGFloat *)bPtr fromCo unsigned char pixel[4]; CGContextRef context = CGBitmapContextCreate(&pixel, 1, 1, 8, 4, rgbColorSpace, kCGImageAlphaNoneSkipLast); - CGContextSetFillColorWithColor(context, [color CGColor]); + CGContextSetFillColorWithColor(context, color.CGColor); CGContextFillRect(context, CGRectMake(0, 0, 1, 1)); if (rPtr) { *rPtr = pixel[0] / 255.0f; } @@ -810,7 +810,7 @@ + (DDTTYLogger *)sharedInstance return sharedInstance; } -- (id)init +- (instancetype)init { if (sharedInstance != nil) { @@ -831,7 +831,7 @@ - (id)init // Initialze 'app' variable (char *) - appName = [[NSProcessInfo processInfo] processName]; + appName = [NSProcessInfo processInfo].processName; appLen = [appName lengthOfBytesUsingEncoding:NSUTF8StringEncoding]; app = (char *)malloc(appLen + 1); @@ -899,7 +899,7 @@ - (void)setColorsEnabled:(BOOL)newColorsEnabled colorsEnabled = newColorsEnabled; - if ([colorProfilesArray count] == 0) { + if (colorProfilesArray.count == 0) { [self loadDefaultColorProfiles]; } }}; @@ -952,8 +952,8 @@ - (void)setForegroundColor:(OSColor *)txtColor backgroundColor:(OSColor *)bgColo i++; } - if (i < [colorProfilesArray count]) - [colorProfilesArray replaceObjectAtIndex:i withObject:newColorProfile]; + if (i < colorProfilesArray.count) + colorProfilesArray[i] = newColorProfile; else [colorProfilesArray addObject:newColorProfile]; }}; @@ -990,7 +990,7 @@ - (void)setForegroundColor:(OSColor *)txtColor backgroundColor:(OSColor *)bgColo NSLogInfo(@"DDTTYLogger: newColorProfile: %@", newColorProfile); - [colorProfilesDict setObject:newColorProfile forKey:tag]; + colorProfilesDict[tag] = newColorProfile; }}; // The design of the setter logic below is taken from the DDAbstractLogger implementation. @@ -1031,7 +1031,7 @@ - (void)clearColorsForFlag:(int)mask context:(int)context i++; } - if (i < [colorProfilesArray count]) + if (i < colorProfilesArray.count) { [colorProfilesArray removeObjectAtIndex:i]; } @@ -1179,7 +1179,7 @@ - (void)logMessage:(DDLogMessage *)logMessage { if (logMessage->tag) { - colorProfile = [colorProfilesDict objectForKey:logMessage->tag]; + colorProfile = colorProfilesDict[logMessage->tag]; } if (colorProfile == nil) { @@ -1263,7 +1263,7 @@ - (void)logMessage:(DDLogMessage *)logMessage NSDateComponents *components = [calendar components:calendarUnitFlags fromDate:logMessage->timestamp]; - NSTimeInterval epoch = [logMessage->timestamp timeIntervalSinceReferenceDate]; + NSTimeInterval epoch = logMessage->timestamp.timeIntervalSinceReferenceDate; int milliseconds = (int)((epoch - floor(epoch)) * 1000); char ts[24]; @@ -1367,7 +1367,7 @@ - (NSString *)loggerName @implementation DDTTYLoggerColorProfile -- (id)initWithForegroundColor:(OSColor *)fgColor backgroundColor:(OSColor *)bgColor flag:(int)aMask context:(int)ctxt +- (instancetype)initWithForegroundColor:(OSColor *)fgColor backgroundColor:(OSColor *)bgColor flag:(int)aMask context:(int)ctxt { if ((self = [super init])) { @@ -1398,7 +1398,7 @@ - (id)initWithForegroundColor:(OSColor *)fgColor backgroundColor:(OSColor *)bgCo // Map foreground color to closest available shell color fgCodeIndex = [DDTTYLogger codeIndexForColor:fgColor]; - fgCodeRaw = [codes_fg objectAtIndex:fgCodeIndex]; + fgCodeRaw = codes_fg[fgCodeIndex]; NSString *escapeSeq = @"\033["; @@ -1433,7 +1433,7 @@ - (id)initWithForegroundColor:(OSColor *)fgColor backgroundColor:(OSColor *)bgCo // Map background color to closest available shell color bgCodeIndex = [DDTTYLogger codeIndexForColor:bgColor]; - bgCodeRaw = [codes_bg objectAtIndex:bgCodeIndex]; + bgCodeRaw = codes_bg[bgCodeIndex]; NSString *escapeSeq = @"\033["; diff --git a/Lumberjack/Extensions/ContextFilterLogFormatter.h b/Lumberjack/Extensions/ContextFilterLogFormatter.h index dffc865..b203b96 100755 --- a/Lumberjack/Extensions/ContextFilterLogFormatter.h +++ b/Lumberjack/Extensions/ContextFilterLogFormatter.h @@ -33,12 +33,12 @@ **/ @interface ContextWhitelistFilterLogFormatter : NSObject -- (id)init; +- (instancetype)init; - (void)addToWhitelist:(int)loggingContext; - (void)removeFromWhitelist:(int)loggingContext; -- (NSArray *)whitelist; +@property (NS_NONATOMIC_IOSONLY, readonly, copy) NSArray *whitelist; - (BOOL)isOnWhitelist:(int)loggingContext; @@ -53,12 +53,12 @@ **/ @interface ContextBlacklistFilterLogFormatter : NSObject -- (id)init; +- (instancetype)init; - (void)addToBlacklist:(int)loggingContext; - (void)removeFromBlacklist:(int)loggingContext; -- (NSArray *)blacklist; +@property (NS_NONATOMIC_IOSONLY, readonly, copy) NSArray *blacklist; - (BOOL)isOnBlacklist:(int)loggingContext; diff --git a/Lumberjack/Extensions/ContextFilterLogFormatter.m b/Lumberjack/Extensions/ContextFilterLogFormatter.m index 9c024ac..c4e8678 100755 --- a/Lumberjack/Extensions/ContextFilterLogFormatter.m +++ b/Lumberjack/Extensions/ContextFilterLogFormatter.m @@ -20,7 +20,7 @@ @interface LoggingContextSet : NSObject - (void)addToSet:(int)loggingContext; - (void)removeFromSet:(int)loggingContext; -- (NSArray *)currentSet; +@property (NS_NONATOMIC_IOSONLY, readonly, copy) NSArray *currentSet; - (BOOL)isInSet:(int)loggingContext; @@ -35,7 +35,7 @@ @implementation ContextWhitelistFilterLogFormatter LoggingContextSet *contextSet; } -- (id)init +- (instancetype)init { if ((self = [super init])) { @@ -84,7 +84,7 @@ @implementation ContextBlacklistFilterLogFormatter LoggingContextSet *contextSet; } -- (id)init +- (instancetype)init { if ((self = [super init])) { @@ -134,7 +134,7 @@ @implementation LoggingContextSet NSMutableSet *set; } -- (id)init +- (instancetype)init { if ((self = [super init])) { @@ -168,7 +168,7 @@ - (NSArray *)currentSet OSSpinLockLock(&lock); { - result = [set allObjects]; + result = set.allObjects; } OSSpinLockUnlock(&lock); diff --git a/Lumberjack/Extensions/DispatchQueueLogFormatter.h b/Lumberjack/Extensions/DispatchQueueLogFormatter.h index 9ad8d3f..d1a8daf 100755 --- a/Lumberjack/Extensions/DispatchQueueLogFormatter.h +++ b/Lumberjack/Extensions/DispatchQueueLogFormatter.h @@ -59,7 +59,7 @@ * Standard init method. * Configure using properties as desired. **/ -- (id)init; +- (instancetype)init; /** * The minQueueLength restricts the minimum size of the [detail box]. diff --git a/Lumberjack/Extensions/DispatchQueueLogFormatter.m b/Lumberjack/Extensions/DispatchQueueLogFormatter.m index d348f3d..00bf2be 100755 --- a/Lumberjack/Extensions/DispatchQueueLogFormatter.m +++ b/Lumberjack/Extensions/DispatchQueueLogFormatter.m @@ -28,7 +28,7 @@ @implementation DispatchQueueLogFormatter NSMutableDictionary *_replacements; // _prefix == Only access from within spinlock } -- (id)init +- (instancetype)init { if ((self = [super init])) { @@ -43,7 +43,7 @@ - (id)init // Set default replacements: - [_replacements setObject:@"main" forKey:@"com.apple.main-thread"]; + _replacements[@"com.apple.main-thread"] = @"main"; } return self; } @@ -62,7 +62,7 @@ - (NSString *)replacementStringForQueueLabel:(NSString *)longLabel OSSpinLockLock(&lock); { - result = [_replacements objectForKey:longLabel]; + result = _replacements[longLabel]; } OSSpinLockUnlock(&lock); @@ -74,7 +74,7 @@ - (void)setReplacementString:(NSString *)shortLabel forQueueLabel:(NSString *)lo OSSpinLockLock(&lock); { if (shortLabel) - [_replacements setObject:shortLabel forKey:longLabel]; + _replacements[longLabel] = shortLabel; else [_replacements removeObjectForKey:longLabel]; } @@ -96,8 +96,8 @@ - (NSString *)stringFromDate:(NSDate *)date if (threadUnsafeDateFormatter == nil) { threadUnsafeDateFormatter = [[NSDateFormatter alloc] init]; - [threadUnsafeDateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4]; - [threadUnsafeDateFormatter setDateFormat:dateFormatString]; + threadUnsafeDateFormatter.formatterBehavior = NSDateFormatterBehavior10_4; + threadUnsafeDateFormatter.dateFormat = dateFormatString; } return [threadUnsafeDateFormatter stringFromDate:date]; @@ -109,16 +109,16 @@ - (NSString *)stringFromDate:(NSDate *)date NSString *key = @"DispatchQueueLogFormatter_NSDateFormatter"; - NSMutableDictionary *threadDictionary = [[NSThread currentThread] threadDictionary]; - NSDateFormatter *dateFormatter = [threadDictionary objectForKey:key]; + NSMutableDictionary *threadDictionary = [NSThread currentThread].threadDictionary; + NSDateFormatter *dateFormatter = threadDictionary[key]; if (dateFormatter == nil) { dateFormatter = [[NSDateFormatter alloc] init]; - [dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4]; - [dateFormatter setDateFormat:dateFormatString]; + dateFormatter.formatterBehavior = NSDateFormatterBehavior10_4; + dateFormatter.dateFormat = dateFormatString; - [threadDictionary setObject:dateFormatter forKey:key]; + threadDictionary[key] = dateFormatter; } return [dateFormatter stringFromDate:date]; @@ -159,7 +159,7 @@ - (NSString *)queueThreadLabelForLogMessage:(DDLogMessage *)logMessage if (strcmp(logMessage->queueLabel, names[i]) == 0) { useQueueLabel = NO; - useThreadName = [logMessage->threadName length] > 0; + useThreadName = logMessage->threadName.length > 0; break; } } @@ -167,7 +167,7 @@ - (NSString *)queueThreadLabelForLogMessage:(DDLogMessage *)logMessage else { useQueueLabel = NO; - useThreadName = [logMessage->threadName length] > 0; + useThreadName = logMessage->threadName.length > 0; } if (useQueueLabel || useThreadName) @@ -182,7 +182,7 @@ - (NSString *)queueThreadLabelForLogMessage:(DDLogMessage *)logMessage OSSpinLockLock(&lock); { - abrvLabel = [_replacements objectForKey:fullLabel]; + abrvLabel = _replacements[fullLabel]; } OSSpinLockUnlock(&lock); @@ -198,7 +198,7 @@ - (NSString *)queueThreadLabelForLogMessage:(DDLogMessage *)logMessage // Now use the thread label in the output - NSUInteger labelLength = [queueThreadLabel length]; + NSUInteger labelLength = queueThreadLabel.length; // labelLength > maxQueueLength : truncate // labelLength < minQueueLength : padding diff --git a/QuickStartApp_iOS/HueQuickStartApp-iOS/PHAppDelegate.m b/QuickStartApp_iOS/HueQuickStartApp-iOS/PHAppDelegate.m index d05e79c..b4bba46 100755 --- a/QuickStartApp_iOS/HueQuickStartApp-iOS/PHAppDelegate.m +++ b/QuickStartApp_iOS/HueQuickStartApp-iOS/PHAppDelegate.m @@ -26,7 +26,7 @@ @interface PHAppDelegate () @implementation PHAppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; + self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; /*************************************************** The Hue SDK is created as a property in the App delegate .h file @@ -91,15 +91,15 @@ - (void)applicationDidEnterBackground:(UIApplication *)application { // Remove any open popups if (self.noConnectionAlert != nil) { - [self.noConnectionAlert dismissWithClickedButtonIndex:[self.noConnectionAlert cancelButtonIndex] animated:NO]; + [self.noConnectionAlert dismissWithClickedButtonIndex:(self.noConnectionAlert).cancelButtonIndex animated:NO]; self.noConnectionAlert = nil; } if (self.noBridgeFoundAlert != nil) { - [self.noBridgeFoundAlert dismissWithClickedButtonIndex:[self.noBridgeFoundAlert cancelButtonIndex] animated:NO]; + [self.noBridgeFoundAlert dismissWithClickedButtonIndex:(self.noBridgeFoundAlert).cancelButtonIndex animated:NO]; self.noBridgeFoundAlert = nil; } if (self.authenticationFailedAlert != nil) { - [self.authenticationFailedAlert dismissWithClickedButtonIndex:[self.authenticationFailedAlert cancelButtonIndex] animated:NO]; + [self.authenticationFailedAlert dismissWithClickedButtonIndex:(self.authenticationFailedAlert).cancelButtonIndex animated:NO]; self.authenticationFailedAlert = nil; } } @@ -153,7 +153,7 @@ - (void)notAuthenticated { // Remove no connection alert if (self.noConnectionAlert != nil) { - [self.noConnectionAlert dismissWithClickedButtonIndex:[self.noConnectionAlert cancelButtonIndex] animated:YES]; + [self.noConnectionAlert dismissWithClickedButtonIndex:(self.noConnectionAlert).cancelButtonIndex animated:YES]; self.noConnectionAlert = nil; } @@ -191,7 +191,7 @@ - (void)checkConnectionState { // One of the connections is made, remove popups and loading views if (self.noConnectionAlert != nil) { - [self.noConnectionAlert dismissWithClickedButtonIndex:[self.noConnectionAlert cancelButtonIndex] animated:YES]; + [self.noConnectionAlert dismissWithClickedButtonIndex:(self.noConnectionAlert).cancelButtonIndex animated:YES]; self.noConnectionAlert = nil; } [self removeLoadingView]; diff --git a/QuickStartApp_iOS/HueQuickStartApp-iOS/PHControlLightsViewController.m b/QuickStartApp_iOS/HueQuickStartApp-iOS/PHControlLightsViewController.m index b91eb81..8a4f67c 100644 --- a/QuickStartApp_iOS/HueQuickStartApp-iOS/PHControlLightsViewController.m +++ b/QuickStartApp_iOS/HueQuickStartApp-iOS/PHControlLightsViewController.m @@ -21,7 +21,7 @@ @interface PHControlLightsViewController() @implementation PHControlLightsViewController -- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil +- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { @@ -90,8 +90,8 @@ - (void)loadConnectedBridgeValues{ // Show current time as last successful heartbeat time when we are connected to a bridge NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; - [dateFormatter setDateStyle:NSDateFormatterNoStyle]; - [dateFormatter setTimeStyle:NSDateFormatterMediumStyle]; + dateFormatter.dateStyle = NSDateFormatterNoStyle; + dateFormatter.timeStyle = NSDateFormatterMediumStyle; self.bridgeLastHeartbeatLabel.text = [NSString stringWithFormat:@"%@",[dateFormatter stringFromDate:[NSDate date]]]; @@ -117,9 +117,9 @@ - (IBAction)randomizeColoursOfConnectLights:(id)sender{ PHLightState *lightState = [[PHLightState alloc] init]; - [lightState setHue:[NSNumber numberWithInt:arc4random() % MAX_HUE]]; - [lightState setBrightness:[NSNumber numberWithInt:254]]; - [lightState setSaturation:[NSNumber numberWithInt:254]]; + lightState.hue = [NSNumber numberWithInt:arc4random() % MAX_HUE]; + lightState.brightness = @254; + lightState.saturation = @254; // Send lightstate to light [bridgeSendAPI updateLightStateForId:light.identifier withLightState:lightState completionHandler:^(NSArray *errors) { diff --git a/QuickStartApp_iOS/SDKWizard/LoadingView/PHLoadingViewController.m b/QuickStartApp_iOS/SDKWizard/LoadingView/PHLoadingViewController.m index 53d969c..498cecf 100755 --- a/QuickStartApp_iOS/SDKWizard/LoadingView/PHLoadingViewController.m +++ b/QuickStartApp_iOS/SDKWizard/LoadingView/PHLoadingViewController.m @@ -11,7 +11,7 @@ @interface PHLoadingViewController () @implementation PHLoadingViewController -- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { +- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Make sure it stays fullscreen diff --git a/QuickStartApp_iOS/SDKWizard/PHBridgePushLinkViewController.h b/QuickStartApp_iOS/SDKWizard/PHBridgePushLinkViewController.h index c4509d5..df29434 100755 --- a/QuickStartApp_iOS/SDKWizard/PHBridgePushLinkViewController.h +++ b/QuickStartApp_iOS/SDKWizard/PHBridgePushLinkViewController.h @@ -44,7 +44,7 @@ @param hueSdk the hue sdk instance to use @param delegate the delegate to inform when pushlinking is done */ -- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil hueSDK:(PHHueSDK *)hueSdk delegate:(id)delegate; +- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil hueSDK:(PHHueSDK *)hueSdk delegate:(id)delegate NS_DESIGNATED_INITIALIZER; /** Start the pushlinking process diff --git a/QuickStartApp_iOS/SDKWizard/PHBridgePushLinkViewController.m b/QuickStartApp_iOS/SDKWizard/PHBridgePushLinkViewController.m index c281305..9d87de5 100755 --- a/QuickStartApp_iOS/SDKWizard/PHBridgePushLinkViewController.m +++ b/QuickStartApp_iOS/SDKWizard/PHBridgePushLinkViewController.m @@ -12,7 +12,7 @@ @interface PHBridgePushLinkViewController () @implementation PHBridgePushLinkViewController -- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil hueSDK:(PHHueSDK *)hueSdk delegate:(id)delegate { +- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil hueSDK:(PHHueSDK *)hueSdk delegate:(id)delegate { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Make it a form on iPad @@ -92,7 +92,7 @@ - (void)authenticationFailed { // Inform delegate [self.delegate pushlinkFailed:[PHError errorWithDomain:SDK_ERROR_DOMAIN code:PUSHLINK_TIME_LIMIT_REACHED - userInfo:[NSDictionary dictionaryWithObject:@"Authentication failed: time limit reached." forKey:NSLocalizedDescriptionKey]]]; + userInfo:@{NSLocalizedDescriptionKey: @"Authentication failed: time limit reached."}]]; } /** @@ -105,7 +105,7 @@ - (void)noLocalConnection { // Inform delegate [self.delegate pushlinkFailed:[PHError errorWithDomain:SDK_ERROR_DOMAIN code:PUSHLINK_NO_CONNECTION - userInfo:[NSDictionary dictionaryWithObject:@"Authentication failed: No local connection to bridge." forKey:NSLocalizedDescriptionKey]]]; + userInfo:@{NSLocalizedDescriptionKey: @"Authentication failed: No local connection to bridge."}]]; } /** @@ -116,7 +116,7 @@ - (void)noLocalBridge { [[PHNotificationManager defaultManager] deregisterObjectForAllNotifications:self]; // Inform delegate - [self.delegate pushlinkFailed:[PHError errorWithDomain:SDK_ERROR_DOMAIN code:PUSHLINK_NO_LOCAL_BRIDGE userInfo:[NSDictionary dictionaryWithObject:@"Authentication failed: No local bridge found." forKey:NSLocalizedDescriptionKey]]]; + [self.delegate pushlinkFailed:[PHError errorWithDomain:SDK_ERROR_DOMAIN code:PUSHLINK_NO_LOCAL_BRIDGE userInfo:@{NSLocalizedDescriptionKey: @"Authentication failed: No local bridge found."}]]; } /** @@ -126,10 +126,10 @@ - (void)noLocalBridge { - (void)buttonNotPressed:(NSNotification *)notification { // Update status bar with percentage from notification NSDictionary *dict = notification.userInfo; - NSNumber *progressPercentage = [dict objectForKey:@"progressPercentage"]; + NSNumber *progressPercentage = dict[@"progressPercentage"]; // Convert percentage to the progressbar scale - float progressBarValue = [progressPercentage floatValue] / 100.0f; + float progressBarValue = progressPercentage.floatValue / 100.0f; self.progressView.progress = progressBarValue; } diff --git a/QuickStartApp_iOS/SDKWizard/PHBridgeSelectionViewController.h b/QuickStartApp_iOS/SDKWizard/PHBridgeSelectionViewController.h index d1032c1..0dfd465 100755 --- a/QuickStartApp_iOS/SDKWizard/PHBridgeSelectionViewController.h +++ b/QuickStartApp_iOS/SDKWizard/PHBridgeSelectionViewController.h @@ -38,6 +38,6 @@ @param bridges the bridges to show in the list @param delegate the delegate to inform when a bridge is selected */ -- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil bridges:(NSDictionary *)bridges delegate:(id)delegate; +- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil bridges:(NSDictionary *)bridges delegate:(id)delegate NS_DESIGNATED_INITIALIZER; @end diff --git a/QuickStartApp_iOS/SDKWizard/PHBridgeSelectionViewController.m b/QuickStartApp_iOS/SDKWizard/PHBridgeSelectionViewController.m index 358af1e..5cd16ba 100755 --- a/QuickStartApp_iOS/SDKWizard/PHBridgeSelectionViewController.m +++ b/QuickStartApp_iOS/SDKWizard/PHBridgeSelectionViewController.m @@ -12,7 +12,7 @@ @interface PHBridgeSelectionViewController () @implementation PHBridgeSelectionViewController -- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil bridges:(NSDictionary *)bridges delegate:(id)delegate { +- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil bridges:(NSDictionary *)bridges delegate:(id)delegate { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Make it a form on iPad @@ -69,8 +69,8 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N NSArray *sortedKeys = [self.bridgesFound.allKeys sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]; // Get mac address and ip address of selected bridge - NSString *bridgeId = [sortedKeys objectAtIndex:indexPath.row]; - NSString *ip = [self.bridgesFound objectForKey:bridgeId]; + NSString *bridgeId = sortedKeys[indexPath.row]; + NSString *ip = (self.bridgesFound)[bridgeId]; // Update cell cell.textLabel.text = bridgeId; @@ -94,8 +94,8 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *****************************************************/ // Get bridge id and ip address of selected bridge - NSString *bridgeId = [sortedKeys objectAtIndex:indexPath.row]; - NSString *ip = [self.bridgesFound objectForKey:bridgeId]; + NSString *bridgeId = sortedKeys[indexPath.row]; + NSString *ip = (self.bridgesFound)[bridgeId]; // Inform delegate [self.delegate bridgeSelectedWithIpAddress:ip andBridgeId:bridgeId];