Skip to content

Instantly share code, notes, and snippets.

@stefc
Created March 12, 2016 19:54
Show Gist options
  • Save stefc/7fe2c90b92b5e63bc259 to your computer and use it in GitHub Desktop.
Save stefc/7fe2c90b92b5e63bc259 to your computer and use it in GitHub Desktop.
sequence for generate int32 identifiers in Swift
//
// IdGenerator.swift
// Created by Stefan Böther on 21.12.15.
//
import Foundation
class IdSequence : SequenceType {
func generate() -> AnyGenerator<Int32> {
var value : Int32 = 0
return anyGenerator {
return OSAtomicIncrement32(&value)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment