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.
		
		
		
		
		
			
		
			
	
	
		
			29 lines
		
	
	
		
			675 B
		
	
	
	
		
			Swift
		
	
		
		
			
		
	
	
			29 lines
		
	
	
		
			675 B
		
	
	
	
		
			Swift
		
	
| 
								 
											9 years ago
										 
									 | 
							
								//
							 | 
						||
| 
								 
											8 years ago
										 
									 | 
							
								//  Copyright (c) 2018 Open Whisper Systems. All rights reserved.
							 | 
						||
| 
								 
											9 years ago
										 
									 | 
							
								//
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * Container for a weakly referenced object.
							 | 
						||
| 
								 | 
							
								 *
							 | 
						||
| 
								 | 
							
								 * Only use this for |T| with reference-semantic entities
							 | 
						||
| 
								 
											8 years ago
										 
									 | 
							
								 * That is - <T> should inherit from AnyObject or Class-only protocols, but not structs or enums.
							 | 
						||
| 
								 
											9 years ago
										 
									 | 
							
								 *
							 | 
						||
| 
								 | 
							
								 * Based on https://devforums.apple.com/message/981472#981472, but also supports class-only protocols
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 
											8 years ago
										 
									 | 
							
								public struct Weak<T> {
							 | 
						||
| 
								 
											9 years ago
										 
									 | 
							
								    private weak var _value: AnyObject?
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											8 years ago
										 
									 | 
							
								    public var value: T? {
							 | 
						||
| 
								 
											9 years ago
										 
									 | 
							
								        get {
							 | 
						||
| 
								 | 
							
								            return _value as? T
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								        set {
							 | 
						||
| 
								 | 
							
								            _value = newValue as AnyObject
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											8 years ago
										 
									 | 
							
								    public init(value: T) {
							 | 
						||
| 
								 
											9 years ago
										 
									 | 
							
								        self.value = value
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								}
							 |