当前位置:网站首页>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边栏推荐
- 手机上券商开户哪个券商平台更好更安全,如果需要佣金低的怎么办
- OpenCvSharp (C# OpenCV) 微信QRCode解码功能使用介绍(附源码)
- #yyds干货盘点#尾递归比递归好在哪儿
- 在一条DML语句中插入/更新/删除/获取几百万行数据,你会特别注意什么?
- Shell view help
- Kunlundb query optimization (II) project and filter push down
- 工程目录导航
- [go] go mod mode, package 12import/add is not in goroot
- Flowable global listener monitors the start and end of a process
- 通过天天基金投资基金安全吗?我打算开户买基金
猜你喜欢

数据库每日一题---第20天:按日期分组销售产品

New paradigm of semantic segmentation! Structtoken: Rethinking the per pixel classification paradigm

How to refine permissions to buttons?

數據庫中數據的儲存結構和方式是什麼?

cadence SPB17.4 - allegro - 优化指定单条电气线折线连接角度 - 折线转圆弧

BGP联邦综合实验

如何入门机器学习?

ROS1Noetic在Win11中安装记录

Mysql8.0 easily completes gtid master-slave replication

百度交易中台之钱包系统架构浅析
随机推荐
[go] go polymorphism
EasyCVR使用RTMP推流时不显示界面如何解决?
图神经网络有哪些用途和应用?
声网多人视频录制与合成支持掉线再录制 | 掘金技术征文
Kunlundb backup and recovery
【机器学习-西瓜书】更文挑战【Day1】:1.1 引言
Redistemplate encountered problems with \x00
华为云招募工业智能领域合作伙伴,强力扶持+商业变现
XML escape character cross reference table
How to refine permissions to buttons?
黄金etf持仓量如何算
【PHP】php多态
你踩过这些坑吗?谨慎在时间类型列上创建索引
Tidb monitoring upgrade: a long way to solve panic
Package management tools --npm, -cnpm, -yan, -cyarn
Shell 日志与打印输出
因为我说:volatile 是轻量级的 synchronized,面试官让我回去等通知!
SAP UI5 应用开发教程之一百零三 - 如何在 SAP UI5 应用中消费第三方库试读版
Why do we not use foreign keys now (2)?
初学者如何快速入门深度学习?