ArrayUtil.swift 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. //
  2. // ArrayUtil.swift
  3. // HCQuanfangtong
  4. //
  5. // Created by Apple on 2022/8/2.
  6. // Copyright © 2022 Jyp. All rights reserved.
  7. //
  8. import Foundation
  9. import CoreAudio
  10. extension Array{
  11. /// 是否可以添加
  12. /// - Parameter index: <#index description#>
  13. /// - Returns: <#description#>
  14. func canInsert(at index: Int) -> (Bool, Int){
  15. var index = index
  16. if self.count == 0{
  17. index = 0
  18. }
  19. else{
  20. if index > self.count{
  21. index = self.count
  22. }
  23. if index < 0 {
  24. index = 0
  25. }
  26. }
  27. return (true, index)
  28. }
  29. /// 是否可以删除
  30. /// - Parameter index: <#index description#>
  31. /// - Returns: <#description#>
  32. func canDelete(at index: Int) -> (Bool, Int){
  33. if self.count == 0{
  34. return (false, 0)
  35. }
  36. var index = index
  37. if index > self.count - 1{
  38. index = self.count - 1
  39. }
  40. if index < 0 {
  41. index = 0
  42. }
  43. return (true, index)
  44. }
  45. /// 是否可以查询到
  46. /// - Parameter index: <#index description#>
  47. /// - Returns: <#description#>
  48. func canGet(at index: Int) -> (Bool, Int){
  49. if self.count == 0{
  50. return (false, 0)
  51. }
  52. var index = index
  53. if index > self.count - 1{
  54. index = self.count - 1
  55. }
  56. if index < 0{
  57. index = 0
  58. }
  59. return (true, index)
  60. }
  61. }