├── .gitattributes ├── .gitignore ├── .swift-version ├── Assets └── EFSafeArray.png ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── Cartfile ├── Cartfile.resolved ├── EFSafeArray.podspec ├── EFSafeArray ├── EFSafeArray.h ├── EFSafeArray.swift ├── Info-tvOS.plist └── Info.plist ├── ISSUE_TEMPLATE.md ├── LICENSE ├── Package.swift ├── README.md ├── Startup.sh └── _config.yml /.gitattributes: -------------------------------------------------------------------------------- 1 | *.* linguist-language=Swift 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # OS X 2 | .DS_Store 3 | 4 | # Xcode 5 | build/ 6 | *.pbxuser 7 | !default.pbxuser 8 | *.mode1v3 9 | !default.mode1v3 10 | *.mode2v3 11 | !default.mode2v3 12 | *.perspectivev3 13 | !default.perspectivev3 14 | xcuserdata/ 15 | *.xccheckout 16 | profile 17 | *.moved-aside 18 | DerivedData 19 | *.hmap 20 | *.ipa 21 | 22 | # SPM 23 | .build 24 | .build/ 25 | 26 | # Bundler 27 | .bundle 28 | 29 | Carthage 30 | # We recommend against adding the Pods directory to your .gitignore. However 31 | # you should judge for yourself, the pros and cons are mentioned at: 32 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 33 | # 34 | # Note: if you ignore the Pods directory, make sure to uncomment 35 | # `pod install` in .travis.yml 36 | # 37 | # Pods/ 38 | 39 | # SPM 40 | .swiftpm 41 | -------------------------------------------------------------------------------- /.swift-version: -------------------------------------------------------------------------------- 1 | 6.0 -------------------------------------------------------------------------------- /Assets/EFSafeArray.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EFPrefix/EFSafeArray/365bc905b632b271b89e888e5cfd991a594d7db9/Assets/EFSafeArray.png -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | ----- 4 | 5 | ## [6.0.0.0](https://github.com/EFPrefix/EFSafeArray/releases/tag/6.0.0.0) (2025-02-12) 6 | 7 | - Adapt to Swift 6.0. 8 | 9 | --- 10 | 11 | ## [5.1.4](https://github.com/EFPrefix/EFSafeArray/releases/tag/5.1.4) (2023-07-23) 12 | 13 | - Fix `Package.swift`. 14 | 15 | --- 16 | 17 | ## [5.1.3](https://github.com/EFPrefix/EFSafeArray/releases/tag/5.1.3) (2022-11-13) 18 | 19 | * Update deployment_target to meet xcode requirements. 20 | 21 | --- 22 | 23 | ## [5.1.2](https://github.com/EFPrefix/EFSafeArray/releases/tag/5.1.2) (2021-06-30) 24 | 25 | * Fix SPM. 26 | 27 | --- 28 | 29 | ## [5.1.1](https://github.com/EFPrefix/EFSafeArray/releases/tag/5.1.1) (2019-10-09) 30 | 31 | * Support SPM; 32 | * Support Carthage. 33 | 34 | --- 35 | 36 | ## [5.1.0](https://github.com/EFPrefix/EFSafeArray/releases/tag/5.1.0) (2019-06-23) 37 | 38 | * Support macOS & watchOS & tvOS. 39 | 40 | --- 41 | 42 | ## [5.0.0](https://github.com/EFPrefix/EFSafeArray/releases/tag/5.0.0) (2019-03-31) 43 | 44 | * Upgrade to Swift 5.0. 45 | 46 | --- 47 | 48 | ## [4.1.0](https://github.com/EFPrefix/EFSafeArray/releases/tag/4.1.0) (2018-11-06) 49 | 50 | * Upgrade to Swift 4.2. 51 | 52 | --- 53 | 54 | ## [4.0.0](https://github.com/EFPrefix/EFSafeArray/releases/tag/4.0.0) (2017-10-01) 55 | 56 | * Update to Swift 4. 57 | 58 | --- 59 | 60 | ## [0.0.1](https://github.com/EFPrefix/EFSafeArray/releases/tag/0.0.1) (2017-07-29) 61 | 62 | * First public release. 63 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at eyrefree@eyrefree.org. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing Guidelines 2 | 3 | This document contains information and guidelines about contributing to this project. 4 | Please read it before you start participating. 5 | 6 | **Topics** 7 | 8 | * [Asking Questions](#asking-questions) 9 | * [Reporting Issues](#reporting-issues) 10 | * [Developers Certificate of Origin](#developers-certificate-of-origin) 11 | 12 | ## Asking Questions 13 | 14 | We don't use GitHub as a support forum. 15 | For any usage questions that are not specific to the project itself, 16 | please ask on [Stack Overflow](https://stackoverflow.com) instead. 17 | By doing so, you'll be more likely to quickly solve your problem, 18 | and you'll allow anyone else with the same question to find the answer. 19 | This also allows maintainers to focus on improving the project for others. 20 | 21 | ## Reporting Issues 22 | 23 | A great way to contribute to the project 24 | is to send a detailed issue when you encounter an problem. 25 | We always appreciate a well-written, thorough bug report. 26 | 27 | Check that the project issues database 28 | doesn't already include that problem or suggestion before submitting an issue. 29 | If you find a match, add a quick "+1" or "I have this problem too." 30 | Doing this helps prioritize the most common problems and requests. 31 | 32 | When reporting issues, please include the following: 33 | 34 | * The version of Xcode you're using 35 | * The version of iOS or macOS you're targeting 36 | * The full output of any stack trace or compiler error 37 | * A code snippet that reproduces the described behavior, if applicable 38 | * Any other details that would be useful in understanding the problem 39 | 40 | This information will help us review and fix your issue faster. 41 | 42 | ## Developer's Certificate of Origin 43 | 44 | By making a contribution to this project, I certify that: 45 | 46 | - (a) The contribution was created in whole or in part by me and I 47 | have the right to submit it under the open source license 48 | indicated in the file; or 49 | 50 | - (b) The contribution is based upon previous work that, to the best 51 | of my knowledge, is covered under an appropriate open source 52 | license and I have the right under that license to submit that 53 | work with modifications, whether created in whole or in part 54 | by me, under the same open source license (unless I am 55 | permitted to submit under a different license), as indicated 56 | in the file; or 57 | 58 | - (c) The contribution was provided directly to me by some other 59 | person who certified (a), (b) or (c) and I have not modified 60 | it. 61 | 62 | - (d) I understand and agree that this project and the contribution 63 | are public and that a record of the contribution (including all 64 | personal information I submit with it, including my sign-off) is 65 | maintained indefinitely and may be redistributed consistent with 66 | this project or the open source license(s) involved. 67 | 68 | --- 69 | 70 | *Some of the ideas and wording for the statements above were based on work by the [Alamofire](https://github.com/Alamofire/Alamofire/blob/master/CONTRIBUTING.md) communities. We commend them for their efforts to facilitate collaboration in their projects.* 71 | -------------------------------------------------------------------------------- /Cartfile: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EFPrefix/EFSafeArray/365bc905b632b271b89e888e5cfd991a594d7db9/Cartfile -------------------------------------------------------------------------------- /Cartfile.resolved: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EFPrefix/EFSafeArray/365bc905b632b271b89e888e5cfd991a594d7db9/Cartfile.resolved -------------------------------------------------------------------------------- /EFSafeArray.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = 'EFSafeArray' 3 | s.version = '6.0.0.0' 4 | s.summary = 'EFSafeArray is an extension to make Array subscript safe.' 5 | 6 | s.description = <<-DESC 7 | EFSafeArray is an extension to make array subscript safe, nil will be return instead of crash if index is out of range. 8 | DESC 9 | 10 | s.homepage = 'https://github.com/EFPrefix/EFSafeArray' 11 | s.screenshots = 'https://raw.githubusercontent.com/EFPrefix/EFSafeArray/master/Assets/EFSafeArray.png' 12 | s.license = { :type => 'MIT', :file => 'LICENSE' } 13 | s.author = { 'EyreFree' => 'eyrefree@eyrefree.org' } 14 | s.source = { :git => 'https://github.com/EFPrefix/EFSafeArray.git', :tag => s.version.to_s } 15 | s.social_media_url = 'https://twitter.com/EyreFree777' 16 | 17 | s.swift_version = "6.0" 18 | 19 | s.ios.deployment_target = '12.0' 20 | s.osx.deployment_target = '10.13' 21 | s.tvos.deployment_target = '12.0' 22 | s.watchos.deployment_target = '6.0' 23 | s.visionos.deployment_target = '1.0' 24 | 25 | s.requires_arc = true 26 | s.source_files = 'EFSafeArray/*.{h,swift}' 27 | 28 | s.frameworks = 'Foundation' 29 | end 30 | -------------------------------------------------------------------------------- /EFSafeArray/EFSafeArray.h: -------------------------------------------------------------------------------- 1 | // 2 | // EFSafeArray.h 3 | // EFSafeArray 4 | // 5 | // Created by EyreFree on 2019/10/9. 6 | // 7 | // Copyright (c) 2017 EyreFree 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in 17 | // all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | // THE SOFTWARE. 26 | 27 | @import Foundation; 28 | 29 | FOUNDATION_EXPORT double EFSafeArrayVersionNumber; 30 | FOUNDATION_EXPORT const unsigned char EFSafeArrayVersionString[]; 31 | -------------------------------------------------------------------------------- /EFSafeArray/EFSafeArray.swift: -------------------------------------------------------------------------------- 1 | // 2 | // EFSafeArray.swift 3 | // EFSafeArray 4 | // 5 | // Created by EyreFree on 2017/7/28. 6 | // 7 | // Copyright (c) 2017 EyreFree 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in 17 | // all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | // THE SOFTWARE. 26 | 27 | import Foundation 28 | 29 | // ~ 30 | postfix operator ~ 31 | public postfix func ~ (value: Int?) -> EFSafeInt? { 32 | return EFSafeInt(value: value) 33 | } 34 | public postfix func ~ (value: Range?) -> EFSafeRange? { 35 | return EFSafeRange(value: value) 36 | } 37 | public postfix func ~ (value: CountableClosedRange?) -> EFSafeRange? { 38 | guard let value = value else { 39 | return nil 40 | } 41 | return EFSafeRange(value: Range(value)) 42 | } 43 | 44 | // Struct 45 | public struct EFSafeInt { 46 | var index: Int 47 | init?(value: Int?) { 48 | guard let value = value else { 49 | return nil 50 | } 51 | self.index = value 52 | } 53 | } 54 | 55 | public struct EFSafeRange { 56 | var range: Range 57 | init?(value: Range?) { 58 | guard let value = value else { 59 | return nil 60 | } 61 | self.range = value 62 | } 63 | } 64 | 65 | // Core 66 | public extension Array { 67 | subscript(index: EFSafeInt?) -> Element? { 68 | get { 69 | if let index = index?.index { 70 | return (self.startIndex.. ArraySlice? { 84 | get { 85 | if let range = bounds?.range { 86 | return self[range.clamped(to: self.startIndex ..< self.endIndex)] 87 | } 88 | return nil 89 | } 90 | set { 91 | if let range = bounds?.range, let newValue = newValue { 92 | self[range.clamped(to: self.startIndex ..< self.endIndex)] = newValue 93 | } 94 | } 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /EFSafeArray/Info-tvOS.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(CURRENT_PROJECT_VERSION) 23 | NSPrincipalClass 24 | 25 | UIRequiredDeviceCapabilities 26 | 27 | arm64 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /EFSafeArray/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(CURRENT_PROJECT_VERSION) 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ### Check List 2 | 3 | Thanks for considering to open an issue. Before you submit your issue, please confirm these boxes are checked. 4 | 5 | - [ ] I have read the [README.md](https://github.com/EFPrefix/EFSafeArray/blob/master/README.md), but there is no information I need. 6 | - [ ] I have searched in [existing issues](https://github.com/EFPrefix/EFSafeArray/issues?utf8=%E2%9C%93&q=is%3Aissue), but did find a same one. 7 | 8 | ### Issue Description 9 | 10 | #### Description 11 | 12 | [Tell us about the issue] 13 | 14 | #### Reproduce 15 | 16 | [The steps to reproduce this issue. What are the parameters, where did you put your code, etc.] 17 | 18 | #### Other Comment 19 | 20 | [Add anything else here] 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017 EyreFree 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:6.0 2 | // 3 | // Package.swift 4 | // EFSafeArray 5 | // 6 | // Created by EyreFree on 2019/10/8. 7 | // 8 | // Copyright (c) 2019 EyreFree 9 | // 10 | // Permission is hereby granted, free of charge, to any person obtaining a copy 11 | // of this software and associated documentation files (the "Software"), to deal 12 | // in the Software without restriction, including without limitation the rights 13 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | // copies of the Software, and to permit persons to whom the Software is 15 | // furnished to do so, subject to the following conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be included in 18 | // all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 26 | // THE SOFTWARE. 27 | 28 | import PackageDescription 29 | 30 | let package = Package( 31 | name: "EFSafeArray", 32 | platforms: [.iOS(.v12), .macOS(.v10_13), .tvOS(.v12), .watchOS(.v6), .visionOS(.v1)], 33 | products: [ 34 | .library(name: "EFSafeArray", targets: ["EFSafeArray"]) 35 | ], 36 | targets: [ 37 | .target(name: "EFSafeArray", path: "EFSafeArray", exclude: ["Info.plist", "Info-tvOS.plist"]) 38 | ], 39 | swiftLanguageVersions: [.v6] 40 | ) 41 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![](https://raw.githubusercontent.com/EFPrefix/EFSafeArray/master/Assets/EFSafeArray.png) 2 | 3 |

4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 |

23 | 24 | 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`. 25 | 26 | ## Example 27 | 28 | To run the example project, clone the repo, and run `pod install` from the Example directory first. 29 | 30 | ## Requirements 31 | 32 | - Xcode 16+ 33 | - Swift 6.0+ 34 | 35 | ## Installation 36 | 37 | ### CocoaPods 38 | 39 | EFSafeArray is available through [CocoaPods](http://cocoapods.org). To install it, simply add the following line to your Podfile: 40 | 41 | ```ruby 42 | pod 'EFSafeArray' 43 | ``` 44 | 45 | ### Swift Package Manager 46 | 47 | The [Swift Package Manager](https://swift.org/package-manager/) is a tool for automating the distribution of Swift code and is integrated into the Swift compiler. 48 | 49 | 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`. 50 | 51 | ```swift 52 | dependencies: [ 53 | .package(url: "https://github.com/EFPrefix/EFSafeArray.git", .upToNextMinor(from: "6.0.0.0")) 54 | ] 55 | ``` 56 | 57 | ## Use 58 | 59 | ```swift 60 | var list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] 61 | // Get Index 62 | let xxx = list[0] // xxx: Int = 1 63 | let zzz = list[0~] // zzz: Int? = 1 64 | let yyy = list[10~] // yyy: Int? = nil 65 | 66 | // Set Index 67 | list[0] = 0 // list = [0, 2, 3, 4, 5, 6, 7, 8, 9, 0] 68 | list[0~] = 1 // list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] 69 | list[10~] = 10 // list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] 70 | 71 | // Get Bounds 72 | let iiii = list[(0...5)~] // iiii: ArraySlice? = [1, 2, 3, 4, 5, 6] 73 | let oooo = list[(-1...12)~] // oooo: ArraySlice? = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] 74 | 75 | // Set Bounds 76 | list[(0...5)~] = [1] // list = [1, 7, 8, 9, 0] 77 | list[(-1...12)~] = [2, 3, 4, 5] // list = [2, 3, 4, 5] 78 | ``` 79 | 80 | ## Author 81 | 82 | EyreFree, eyrefree@eyrefree.org 83 | 84 | ## License 85 | 86 | ![](https://upload.wikimedia.org/wikipedia/commons/thumb/f/f8/License_icon-mit-88x31-2.svg/128px-License_icon-mit-88x31-2.svg.png) 87 | 88 | EFSafeArray is available under the MIT license. See the LICENSE file for more info. 89 | -------------------------------------------------------------------------------- /Startup.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | if ! command -v carthage > /dev/null; then 3 | printf 'Carthage is not installed.\n' 4 | printf 'See https://github.com/Carthage/Carthage for install instructions.\n' 5 | exit 1 6 | fi 7 | carthage update --platform iOS,macOS,tvOS,watchOS --no-use-binaries 8 | # carthage build --platform iOS,macOS,tvOS,watchOS --no-skip-current 9 | 10 | if ! command -v pod > /dev/null; then 11 | printf 'CocoaPods is not installed.\n' 12 | printf 'See https://github.com/CocoaPods/CocoaPods for install instructions.\n' 13 | exit 1 14 | fi 15 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman --------------------------------------------------------------------------------