GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - EFPrefix/EFSafeArray: EFSafeArray is an extension to make array subscript safe, support iOS, macOS, watchOS and tvOS.

BranchesTags
Open more actions menu

Latest commit

 

History

36 Commits
36 Commits

Folders and files

NameName
Last commit message
Last commit date
Assets
Assets
 
 
EFSafeArray
EFSafeArray
 
 
.gitattributes
.gitattributes
 
 
.gitignore
.gitignore
 
 
.swift-version
.swift-version
 
 
CHANGELOG.md
CHANGELOG.md
 
 
CODE_OF_CONDUCT.md
CODE_OF_CONDUCT.md
 
 
CONTRIBUTING.md
CONTRIBUTING.md
 
 
Cartfile
Cartfile
 
 
Cartfile.resolved
Cartfile.resolved
 
 
EFSafeArray.podspec
EFSafeArray.podspec
 
 
ISSUE_TEMPLATE.md
ISSUE_TEMPLATE.md
 
 
LICENSE
LICENSE
 
 
Package.swift
Package.swift
 
 
README.md
README.md
 
 
Startup.sh
Startup.sh
 
 
_config.yml
_config.yml
 
 

Repository files navigation

EFSafeArray is an extension to make array subscript safe, nil will be return instead of crash if index is out of range, it works on iOS, macOS, watchOS and tvOS.

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

  • Xcode 16+
  • Swift 6.0+

Installation

CocoaPods

EFSafeArray is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'EFSafeArray'

Swift Package Manager

The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the Swift compiler.

Once you have your Swift package set up, adding EFSafeArray as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies: [
    .package(url: "https://github.com/EFPrefix/EFSafeArray.git", .upToNextMinor(from: "6.0.0.0"))
]

Use

var list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
// Get Index
let xxx = list[0]               // xxx: Int = 1
let zzz = list[0~]              // zzz: Int? = 1
let yyy = list[10~]             // yyy: Int? = nil

// Set Index
list[0] = 0                     // list = [0, 2, 3, 4, 5, 6, 7, 8, 9, 0]
list[0~] = 1                    // list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
list[10~] = 10                  // list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]

// Get Bounds
let iiii = list[(0...5)~]       // iiii: ArraySlice<Int>? = [1, 2, 3, 4, 5, 6]
let oooo = list[(-1...12)~]     // oooo: ArraySlice<Int>? = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]

// Set Bounds
list[(0...5)~] = [1]            // list = [1, 7, 8, 9, 0]
list[(-1...12)~] = [2, 3, 4, 5] // list = [2, 3, 4, 5]

Author

EyreFree, [email protected]

License

EFSafeArray is available under the MIT license. See the LICENSE file for more info.

About

EFSafeArray is an extension to make array subscript safe, support iOS, macOS, watchOS and tvOS.

swiftpackageindex.com/EFPrefix/EFSafeArray

Topics

arrayautonilrangesafeswift

Resources

Readme
MIT license

Code of conduct

Code of conduct

Contributing

Contributing
Activity
Custom properties

Stars

15 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.