session-ios/SessionUtilitiesKit/Utilities/Optional+Utilities.swift
Morgan Pretty 32304ae5dd Cleared out some of the legacy serialisation logic, further UI binding
Refactored the SignalApp class to Swift
Fixed a horizontal alignment issue in the ConversationTitleView
Fixed an issue where expiration timer update messages weren't migrated or rendering correctly
Fixed an issue where expiring messages weren't migrated correctly
Fixed an issue where closed groups which had been left were causing migration failures (due to data incorrectly being assumed to be required)
Shifted the Legacy Attachment types into the 'SMKLegacy' namespace
Moved all of the NSCoding logic for the TSMessage
2022-05-03 17:14:56 +10:00

32 lines
863 B
Swift

// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
import Foundation
extension Optional {
public func map<U>(_ transform: (Wrapped) throws -> U?) rethrows -> U? {
switch self {
case .some(let value): return try transform(value)
default: return nil
}
}
public func asType<R>(_ type: R.Type) -> R? {
switch self {
case .some(let value): return (value as? R)
default: return nil
}
}
public func defaulting(to value: Wrapped) -> Wrapped {
return (self ?? value)
}
}
extension Optional where Wrapped == String {
public func defaulting(to value: Wrapped, useDefaultIfEmpty: Bool = false) -> Wrapped {
guard !useDefaultIfEmpty || self?.isEmpty != true else { return value }
return (self ?? value)
}
}