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.
		
		
		
		
		
			
		
			
	
	
		
			28 lines
		
	
	
		
			855 B
		
	
	
	
		
			Swift
		
	
		
		
			
		
	
	
			28 lines
		
	
	
		
			855 B
		
	
	
	
		
			Swift
		
	
| 
								 
											5 years ago
										 
									 | 
							
								//
							 | 
						||
| 
								 | 
							
								//  Copyright (c) 2018 Open Whisper Systems. All rights reserved.
							 | 
						||
| 
								 | 
							
								//
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								import Foundation
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								@objc
							 | 
						||
| 
								 | 
							
								public class SSKIncrementingIdFinder: NSObject {
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    @objc
							 | 
						||
| 
								 | 
							
								    public static let collectionName = "IncrementingIdCollection"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    @objc
							 | 
						||
| 
								 | 
							
								    public class func previousId(key: String, transaction: YapDatabaseReadTransaction) -> UInt64 {
							 | 
						||
| 
								 | 
							
								        let previousId: UInt64 = transaction.object(forKey: key, inCollection: collectionName) as? UInt64 ?? 0
							 | 
						||
| 
								 | 
							
								        return previousId
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    @objc
							 | 
						||
| 
								 | 
							
								    public class func nextId(key: String, transaction: YapDatabaseReadWriteTransaction) -> UInt64 {
							 | 
						||
| 
								 | 
							
								        let previousId: UInt64 = transaction.object(forKey: key, inCollection: collectionName) as? UInt64 ?? 0
							 | 
						||
| 
								 | 
							
								        let nextId: UInt64 = previousId + 1
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        transaction.setObject(nextId, forKey: key, inCollection: collectionName)
							 | 
						||
| 
								 | 
							
								        return nextId
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								}
							 |