mirror of https://github.com/oxen-io/session-ios
				
				
				
			
			You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
	
	
		
			25 lines
		
	
	
		
			631 B
		
	
	
	
		
			Swift
		
	
		
		
			
		
	
	
			25 lines
		
	
	
		
			631 B
		
	
	
	
		
			Swift
		
	
| 
								 
											4 years ago
										 
									 | 
							
								// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								import Foundation
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								struct Failable<T: Codable>: Codable {
							 | 
						||
| 
								 | 
							
								    let value: T?
							 | 
						||
| 
								 | 
							
								    
							 | 
						||
| 
								 | 
							
								    init(from decoder: Decoder) throws {
							 | 
						||
| 
								 | 
							
								        guard let container = try? decoder.singleValueContainer() else {
							 | 
						||
| 
								 | 
							
								            self.value = nil
							 | 
						||
| 
								 | 
							
								            return
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								        
							 | 
						||
| 
								 | 
							
								        self.value = try? container.decode(T.self)
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								    
							 | 
						||
| 
								 | 
							
								    func encode(to encoder: Encoder) throws {
							 | 
						||
| 
								 | 
							
								        guard let value: T = value else { return }
							 | 
						||
| 
								 | 
							
								        
							 | 
						||
| 
								 | 
							
								        var container: SingleValueEncodingContainer = encoder.singleValueContainer()
							 | 
						||
| 
								 | 
							
								        
							 | 
						||
| 
								 | 
							
								        try container.encode(value)
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								}
							 |