Fix some compiler warnings

* explicit optional usage in strings
* remove some unused StringUtil code
* swiftlint affected files
* more concise optional casting (and avoid a `!`)

Compiler warnings: 343 -> 318

(Actually most of these are in external libs, but 115 remain in Signal/SSK)

// FREEBIE
pull/1/head
Michael Kirk 8 years ago
parent ce2ee759f8
commit d7c7fff679

@ -188,7 +188,7 @@ class MessageFetcherJob: NSObject {
Logger.debug("\(self.TAG) acknowledged delivery for message at timestamp: \(envelope.timestamp)") Logger.debug("\(self.TAG) acknowledged delivery for message at timestamp: \(envelope.timestamp)")
}, },
failure: { (_: URLSessionDataTask?, error: Error?) in failure: { (_: URLSessionDataTask?, error: Error?) in
Logger.debug("\(self.TAG) acknowledging delivery for message at timestamp: \(envelope.timestamp) failed with error: \(error)") Logger.debug("\(self.TAG) acknowledging delivery for message at timestamp: \(envelope.timestamp) failed with error: \(String(describing: error))")
}) })
} }
} }

@ -1,5 +1,6 @@
// Created by Michael Kirk on 11/15/16. //
// Copyright © 2016 Open Whisper Systems. All rights reserved. // Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
import Foundation import Foundation
@ -7,8 +8,8 @@ let CompareSafetyNumbersActivityType = "org.whispersystems.signal.activity.Compa
@objc(OWSCompareSafetyNumbersActivityDelegate) @objc(OWSCompareSafetyNumbersActivityDelegate)
protocol CompareSafetyNumbersActivityDelegate { protocol CompareSafetyNumbersActivityDelegate {
func compareSafetyNumbersActivitySucceeded(activity: CompareSafetyNumbersActivity) -> Void; func compareSafetyNumbersActivitySucceeded(activity: CompareSafetyNumbersActivity)
func compareSafetyNumbersActivity(_ activity: CompareSafetyNumbersActivity, failedWithError error: Error) -> Void; func compareSafetyNumbersActivity(_ activity: CompareSafetyNumbersActivity, failedWithError error: Error)
} }
@objc (OWSCompareSafetyNumbersActivity) @objc (OWSCompareSafetyNumbersActivity)
@ -59,7 +60,7 @@ class CompareSafetyNumbersActivity: UIActivity {
let pasteboardString = numericOnly(string: UIPasteboard.general.string) let pasteboardString = numericOnly(string: UIPasteboard.general.string)
guard (pasteboardString != nil && pasteboardString!.characters.count == 60) else { guard (pasteboardString != nil && pasteboardString!.characters.count == 60) else {
Logger.warn("\(TAG) no valid safety numbers found in pasteboard: \(pasteboardString)") Logger.warn("\(TAG) no valid safety numbers found in pasteboard: \(String(describing: pasteboardString))")
let error = OWSErrorWithCodeDescription(OWSErrorCode.userError, let error = OWSErrorWithCodeDescription(OWSErrorCode.userError,
NSLocalizedString("PRIVACY_VERIFICATION_FAILED_NO_SAFETY_NUMBERS_IN_CLIPBOARD", comment: "Alert body for user error")) NSLocalizedString("PRIVACY_VERIFICATION_FAILED_NO_SAFETY_NUMBERS_IN_CLIPBOARD", comment: "Alert body for user error"))
@ -70,10 +71,10 @@ class CompareSafetyNumbersActivity: UIActivity {
let pasteboardSafetyNumbers = pasteboardString! let pasteboardSafetyNumbers = pasteboardString!
if pasteboardSafetyNumbers == mySafetyNumbers { if pasteboardSafetyNumbers == mySafetyNumbers {
Logger.info("\(TAG) successfully matched safety numbers. local numbers: \(mySafetyNumbers) pasteboard:\(pasteboardSafetyNumbers)") Logger.info("\(TAG) successfully matched safety numbers. local numbers: \(String(describing: mySafetyNumbers)) pasteboard:\(pasteboardSafetyNumbers)")
delegate.compareSafetyNumbersActivitySucceeded(activity:self) delegate.compareSafetyNumbersActivitySucceeded(activity:self)
} else { } else {
Logger.warn("\(TAG) local numbers: \(mySafetyNumbers) didn't match pasteboard:\(pasteboardSafetyNumbers)") Logger.warn("\(TAG) local numbers: \(String(describing: mySafetyNumbers)) didn't match pasteboard:\(pasteboardSafetyNumbers)")
let error = OWSErrorWithCodeDescription(OWSErrorCode.privacyVerificationFailure, let error = OWSErrorWithCodeDescription(OWSErrorCode.privacyVerificationFailure,
NSLocalizedString("PRIVACY_VERIFICATION_FAILED_MISMATCHED_SAFETY_NUMBERS_IN_CLIPBOARD", comment: "Alert body")) NSLocalizedString("PRIVACY_VERIFICATION_FAILED_MISMATCHED_SAFETY_NUMBERS_IN_CLIPBOARD", comment: "Alert body"))
delegate.compareSafetyNumbersActivity(self, failedWithError: error) delegate.compareSafetyNumbersActivity(self, failedWithError: error)

@ -868,10 +868,8 @@ class CallViewController: UIViewController, CallObserver, CallServiceObserver, R
self.localVideoTrack = localVideoTrack self.localVideoTrack = localVideoTrack
var source: RTCAVFoundationVideoSource? let source = localVideoTrack?.source as? RTCAVFoundationVideoSource
if localVideoTrack?.source is RTCAVFoundationVideoSource {
source = localVideoTrack?.source as! RTCAVFoundationVideoSource
}
localVideoView.captureSession = source?.captureSession localVideoView.captureSession = source?.captureSession
let isHidden = source == nil let isHidden = source == nil
Logger.info("\(TAG) \(#function) isHidden: \(isHidden)") Logger.info("\(TAG) \(#function) isHidden: \(isHidden)")

@ -347,7 +347,7 @@ fileprivate extension CNContact {
@objc var nameForCollating: String { @objc var nameForCollating: String {
get { get {
if self.familyName.isEmpty && self.givenName.isEmpty { if self.familyName.isEmpty && self.givenName.isEmpty {
return self.emailAddresses.first?.value as? String ?? "" return self.emailAddresses.first?.value as String? ?? ""
} }
let compositeName: String let compositeName: String

@ -80,7 +80,7 @@ class SignalAttachment: NSObject {
AssertIsOnMainThread() AssertIsOnMainThread()
assert(oldValue == nil) assert(oldValue == nil)
Logger.verbose("\(SignalAttachment.TAG) Attachment has error: \(error)") Logger.verbose("\(SignalAttachment.TAG) Attachment has error: \(String(describing: error))")
} }
} }

@ -308,7 +308,7 @@ import AVFoundation
Logger.debug("\(self.TAG) set category: \(category) options: \(options)") Logger.debug("\(self.TAG) set category: \(category) options: \(options)")
} }
} catch { } catch {
let message = "\(self.TAG) in \(#function) failed to set category: \(category) mode: \(mode), options: \(options) with error: \(error)" let message = "\(self.TAG) in \(#function) failed to set category: \(category) mode: \(String(describing: mode)), options: \(options) with error: \(error)"
assertionFailure(message) assertionFailure(message)
Logger.error(message) Logger.error(message)
} }

@ -125,7 +125,7 @@ protocol CallServiceObserver: class {
didSet { didSet {
AssertIsOnMainThread() AssertIsOnMainThread()
Logger.debug("\(self.TAG) .peerConnectionClient setter: \(oldValue != nil) -> \(peerConnectionClient != nil) \(peerConnectionClient)") Logger.debug("\(self.TAG) .peerConnectionClient setter: \(oldValue != nil) -> \(peerConnectionClient != nil) \(String(describing: peerConnectionClient))")
} }
} }
@ -141,7 +141,7 @@ protocol CallServiceObserver: class {
updateIsVideoEnabled() updateIsVideoEnabled()
updateLockTimerEnabling() updateLockTimerEnabling()
Logger.debug("\(self.TAG) .call setter: \(oldValue != nil) -> \(call != nil) \(call)") Logger.debug("\(self.TAG) .call setter: \(oldValue != nil) -> \(call != nil) \(String(describing: call))")
for observer in observers { for observer in observers {
observer.value?.didUpdateCall(call:call) observer.value?.didUpdateCall(call:call)
@ -688,7 +688,7 @@ protocol CallServiceObserver: class {
guard thread.contactIdentifier() == self.thread?.contactIdentifier() else { guard thread.contactIdentifier() == self.thread?.contactIdentifier() else {
// This can safely be ignored. // This can safely be ignored.
// We don't want to fail the current call because an old call was slow to send us the hangup message. // We don't want to fail the current call because an old call was slow to send us the hangup message.
Logger.warn("\(TAG) ignoring hangup for thread:\(thread) which is not the current thread: \(self.thread)") Logger.warn("\(TAG) ignoring hangup for thread:\(thread) which is not the current thread: \(String(describing: self.thread))")
return return
} }

@ -1,3 +1,7 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
@interface NSString (Util) @interface NSString (Util)
@ -11,11 +15,9 @@
- (NSString *)withMatchesAgainst:(NSRegularExpression *)regex replacedBy:(NSString *)replacement; - (NSString *)withMatchesAgainst:(NSRegularExpression *)regex replacedBy:(NSString *)replacement;
- (bool)containsAnyMatches:(NSRegularExpression *)regex; - (bool)containsAnyMatches:(NSRegularExpression *)regex;
- (NSString *)withPrefixRemovedElseNull:(NSString *)prefix; - (NSString *)withPrefixRemovedElseNull:(NSString *)prefix;
- (NSData *)decodedAsJsonIntoData;
- (NSDictionary *)decodedAsJsonIntoDictionary; - (NSDictionary *)decodedAsJsonIntoDictionary;
- (NSData *)decodedAsHexString;
- (NSData *)decodedAsSpaceSeparatedHexString;
- (NSData *)decodedAsBase64Data;
- (NSNumber *)tryParseAsDecimalNumber; - (NSNumber *)tryParseAsDecimalNumber;
- (NSNumber *)tryParseAsUnsignedInteger; - (NSNumber *)tryParseAsUnsignedInteger;
- (NSString *)removeAllCharactersIn:(NSCharacterSet *)characterSet; - (NSString *)removeAllCharactersIn:(NSCharacterSet *)characterSet;

@ -6,20 +6,7 @@
#import "StringUtil.h" #import "StringUtil.h"
@implementation NSString (Util) @implementation NSString (Util)
- (NSData *)decodedAsHexString {
ows_require(self.length % 2 == 0);
NSUInteger n = self.length / 2;
uint8_t result[n];
for (NSUInteger i = 0; i < n; i++) {
unsigned int r;
NSScanner *scanner = [NSScanner scannerWithString:[self substringWithRange:NSMakeRange(i * 2, 2)]];
checkOperation([scanner scanHexInt:&r]);
checkOperation(r < 256);
result[i] = (uint8_t)r;
}
return [NSData dataWithBytes:result length:sizeof(result)];
}
- (NSData *)encodedAsUtf8 { - (NSData *)encodedAsUtf8 {
NSData *result = [self dataUsingEncoding:NSUTF8StringEncoding]; NSData *result = [self dataUsingEncoding:NSUTF8StringEncoding];
checkOperationDescribe(result != nil, @"Not a UTF8 string."); checkOperationDescribe(result != nil, @"Not a UTF8 string.");
@ -54,13 +41,6 @@
return nil; return nil;
return [self substringFromIndex:prefix.length]; return [self substringFromIndex:prefix.length];
} }
- (NSData *)decodedAsJsonIntoData {
NSError *jsonParseError = nil;
id parsedJson = [NSJSONSerialization dataWithJSONObject:self.encodedAsUtf8 options:0 error:&jsonParseError];
checkOperationDescribe(jsonParseError == nil, ([NSString stringWithFormat:@"Invalid json: %@", self]));
checkOperationDescribe([parsedJson isKindOfClass:NSData.class], @"Unexpected json data");
return parsedJson;
}
- (NSDictionary *)decodedAsJsonIntoDictionary { - (NSDictionary *)decodedAsJsonIntoDictionary {
NSError *jsonParseError = nil; NSError *jsonParseError = nil;
id parsedJson = [NSJSONSerialization JSONObjectWithData:self.encodedAsUtf8 options:0 error:&jsonParseError]; id parsedJson = [NSJSONSerialization JSONObjectWithData:self.encodedAsUtf8 options:0 error:&jsonParseError];

Loading…
Cancel
Save