当前位置:网站首页>Swiftui swift tutorial 14 useful array operators
Swiftui swift tutorial 14 useful array operators
2022-06-23 00:39:00 【Knowledge fatness】
Arrays allow you to aggregate a large number of values into a single collection , These values are then accessed based on their location in the collection .Swift Use type inference to determine the type of data in the array .
Array declaration :
var arr = [2,3,5]
var arr: [Int] = []
var arr = Array(repeating: 8, count: 3)
1. Add to array
You can add to the end of an array or insert a value at a specific index .append Command or abbreviation += Operators can be used to append , As shown below :
arr.append(5)
arr += [5]
For this task , The two statements are functionally identical . One thing to remember is , In order to use += Operator , You must have an array on the right , Even if it contains only one value . however , If you want to add multiple items to the array , Just add the text to the array , So you can add more values to the array , As shown below :
arr += [9, 8, 7, 6]
[5, 5, 9, 8, 7, 6]
insert The command can also be used to insert values anywhere , for example :
arr.insert(92, at: 2)
//arr now is [5, 5, 92, 9, 8, 7, 6]
2. Remove from array
You can also delete items from the array . If we want to delete something from a given index , We can do that :
let removedValue = arr.remove(at: 3)
//emptyArray now is [5, 5, 92, 8, 7, 6]
removedValue is 9边栏推荐
猜你喜欢

Isolation level of transaction system

How do beginners get started quickly and learn deeply?

ROS2暑期学校 ROS2 Summer School 2022-转-

使用GetX构建更优雅的Flutter页面结构

【GO】go mod模式, package 12import/add is not in GOROOT
因为我说:volatile 是轻量级的 synchronized,面试官让我回去等通知!

SAP UI5 应用开发教程之一百零二 - SAP UI5 应用的打印(Print)功能实现详解试读版

【滑动窗口】leetcode992. Subarrays with K Different Integers

Cadence spb17.4 - Chinese UI settings

XML escape character cross reference table
随机推荐
Oracle ASM使用asmcmd中的cp命令来执行远程复制
3dMax建模笔记(一):介绍3dMax和创建第一个模型Hello world
How to use enum data types
【UVM】别再说你的 VIP 用不了 RAL Model
瑞达期货安全么?期货开户都是哪些流程?期货手续费怎么降低?
How to set the power-off auto start of easycvr hardware box
Dig three feet to solve the data consistency problem between redis and MySQL
【机器学习-西瓜书】更文挑战【Day1】:1.1 引言
SAP UI5 应用开发教程之一百零三 - 如何在 SAP UI5 应用中消费第三方库试读版
一文读懂基于Redis的Amazon MemoryDB数据库
Is it safe to open a new bond? How
EasyCVR硬件盒子如何设置断电自启动
flowable 全局监听 监听流程的启动和流程的结束
SAP mm me27 create intra company sto order
TiDB VS MySQL
中金证券开户安全吗?它和中金银行是什么关系呢?
Oracle ASM uses the CP command in asmcmd to perform remote replication
What financial product does the new bond belong to?
Is it safe for CICC securities to open an account? What is its relationship with CICC?
Package management tools --npm, -cnpm, -yan, -cyarn