mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
32304ae5dd
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
32 lines
863 B
Swift
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)
|
|
}
|
|
}
|