Add logic for more customizable password generator

This commit is contained in:
Danny Moesch 2020-02-28 19:04:53 +01:00 committed by Mingshen Sun
parent 49a371d495
commit ff014a5699
10 changed files with 352 additions and 131 deletions

View file

@ -0,0 +1,28 @@
//
// Array+Slices.swift
// passKit
//
// Created by Danny Moesch on 28.02.20.
// Copyright © 2020 Bob Sun. All rights reserved.
//
extension Array {
func slices(count: UInt) -> [ArraySlice<Element>] {
guard count != 0 else {
return []
}
let sizeEach = Int(self.count / Int(count))
var currentIndex = startIndex
var slices = [ArraySlice<Element>]()
for _ in 0 ..< count {
let toIndex = index(currentIndex, offsetBy: sizeEach, limitedBy: endIndex) ?? endIndex
slices.append(self[currentIndex ..< toIndex])
currentIndex = toIndex
}
if currentIndex != endIndex {
slices[slices.endIndex - 1].append(contentsOf: self[currentIndex ..< endIndex])
}
return slices
}
}