首页 > 其他分享 >Swift基础语法速通(突击学会

Swift基础语法速通(突击学会

时间:2022-10-30 07:33:06浏览次数:27  
标签:速通 Int value 语法 print let var Swift String

Swift Grammar

!从各路教程官方文档节选的内容➕一些个人理解
适合
初学者考试突击

需要短时间快速浏览swift语言特点
的朋友

Introduction

Swift doesn't have header file

Compiled language

Variables、Constants、Literals

Variables Constants
var let

A literal is the source code representation of a value of an integer, floating-point number, or string type.

起名:可以是任意unicode表示的包括pi,包括emoji,但是数学符号箭头空格不行,且不能以数字开头。

Definition:

var siteName:String = "Northeastern"
var id: Int
  • 类型注释 Type annotation: let money : Int = 15
  • 类型推论 Type Inference: let thisIsInteger = 15

Boolean:

Swift has type safety, which prevent non-Boolean values using as bool

即不能用1和0代替true和false

Operations

Range

Operator Description
闭区间 (a...b) defines a range that runs from a to b, and includes the values a and b.
半开半闭区间 (a..< b) defines a range that runs from a to b, but does not include b.
单边区间 a... or ...a defines a range that runs from a to end of elements or form start of elements to a

Ternery Condition

Condition ? X : Y

If Condition is true ? Then value X : Otherwise value Y

Identity Operators

=== and !==

References are to the same object instance

String and Characters

Create Character

let char : Character  = “?”
let catCharacters: [ Character ] = ["C", "a", "t", "!", "

标签:速通,Int,value,语法,print,let,var,Swift,String
From: https://www.cnblogs.com/Lamplight/p/16840427.html

相关文章

  • Markdown排版格式语法(持续更新)
    首行缩进&ensp;半角的空格&emsp;全角的空格需要首行缩进两个字符的话,连续使用以上任意一个两次即可。文本加粗<b>你好</b>文本加粗&&居中&&用黑体<center><font......
  • Vue-基本语法
     Vue:v-bind绑定事件;el:是挂起的含义,“”里填类名; <!DOCTYPEhtml><htmllang="zh-CN"><head><metacharset="UTF-8"/><metahttp-equiv="X-UA-C......
  • 【Swift 60秒】33 - Exiting multiple loops
    0x00LessonIfyouputaloopinsidealoopit’scalleda​​nested​​loop,andit’snotuncommontowanttobreakoutofboththeinnerloopandtheouter......
  • 【Swift 60秒】34 - Skipping items
    0x00LessonAsyou’veseen,the​​break​​​keywordexitsaloop.Butifyoujustwantto​​skip​​​thecurrentitemandcontinueontothenextone,y......
  • 【Swift 60秒】35 - Infinite loops
    0x00LessonIt’scommontouse​​while​​loopstomakeinfiniteloops:loopsthateitherhavenoendoronlyendwhenyou’reready.AllappsonyouriPhone......
  • Terraform 语法 变量的使用
    变量分为两种类型,一种为输入变量,另外一种为输出变量。之前在写tf的模板文件的时候用了很多变量,比如在写认证信息的时候,定义的变量存放了阿里云的ak和sk,最后就是region的信息......
  • Terraform 语法 resource(1)
    resource是我们的资源,一般在terraform里面定义的都是资源,是个非常重要的角色。关键字resource+资源类型(比如dns,ecs,vpc,交换机)+资源的名称。模块下资源的名称要保证唯一,不要冲......
  • Terraform 语法 provider插件
     语法是terraform最重要的一点,有两个部分来讲解,第一部分是基础,第二部分是更加高级的扩展。后面各种实践其实就是对terraform语法编写。第一部分是provider插件,provider提供......
  • 【TypeScript】语法精讲
    TypeScript的编译环境#安装命令npminstalltypescript-g#查看版本tsc--versionTypeScript的运行环境#安装ts-nodenpminstallts-node-g#另外ts-node需要依赖tslib......
  • typeScript基础语法
    1.变量定义变量名:变量的类型(首字母小写)letdan:string='蛋'letnumArr:number[]=[4,2,0];2、核心定义任何东西的时候要注明类型调用任何东西的时候要检查类型3......