//
// ViewController.swift
// 基本数据类型
//
// Created by 叶炯 on 16/9/8.
// Copyright © 2016年 叶炯. All rights reserved.
// import UIKit class ViewController: UIViewController { override func viewDidLoad() {
super.viewDidLoad() // let //常量
// var //变量
//
//使用let 必须初始化 let 的值不可改变 /*
字符,字符串
*/
//字符
var charValuel : Character = "q"
//字符串
var charValue2 : String = "" //初始化一个空的字符串 var charValue3 = ""
var charValue4 = String() //判断一个字符串是否为空
if charValue2.isEmpty {
print("字符串为空") } //或 if charValue3 == "" {
print("字符串为空")
} //给字符串赋值
let emptyString = "abc"
let emptyString2 = String("abc") //遍历一个字符串中的字符
for c in emptyString2.characters { print(c)
} /**
元祖
*/ //元祖内的值可以是任意类型,各元祖不必是相同的类型 //定义一个元祖 let product = (, "iphone 6s", )
print(product)
//获取元祖中的每一个元素
var (_year , _name , _price) = product print("year = \(_year)","_name=\(_name)", "price=\(_price)") //只输入一个值 let (_ ,name1, _) = product
print("name\(name1)") //可以使用点语法 let product2 = (year:, name:"iphone 6s", price:)
print(product2.year)
print(product2.name)
print(product2.price) /*
可选类型
*/ var stringValue : String
// print(stringValue) 编译不会通过, 没有初始化 var stringValue2 : String?
if (stringValue2 != nil) { print(stringValue2!) }
//如果字符串为""使用!打印会崩溃 使用? 输出为nil
//!表示一定有值 ? 表示可能有值
var numStr : String = ""
var value1 : Int? = Int(numStr)
print(value1) /**
数值得可读性
*/ let readabilty1 = ;
let readabilty2 = 1_000_000_000_1 /**
类型别名
*/ //类型别名就是给一个类型重新取一个更有意义的别名(新类型),它使用 typealias 关键字 //格式如下 typealias NewInt = Int32 var new_value : NewInt = print(new_value) /**
基本数据类型之间的转换
*/ // Int类型转换成其他的类型 var j :Int =
Double(j)
Float(j) //String 类型转 Int Float Double 类型 var s : String = "2.156asd2" //当第一个字符不是数字时,转为 Double 就为0
//当字符第一位为数字,可以直接转为数字,,遇到非字符时停止,数值为非字符之前的数字
Int(s)
print("-------",s) var s2 = s as NSString print(s2.integerValue)
print(s2.floatValue)
print(s2.doubleValue) //Double Float Int 转 String var d : Double = 1.68
"\(d)" var f : Float = 3.134
"\(f)" var i :Int =
"\(i)" //不能直接用 String(Int) 可以将字符串的数值使用"\(value)"形式
//Int 可以直接使用 Double(Int) Float(Int) /**
运算符
*/ /**
++i 是 i= i+1 而--i 是 i = i-1 */
//一元运算符
let three = -
let minusThree = -three
let plusThree = -minusThree print(minusThree, plusThree) //as 类型转换
//is 类型检查 } override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
} }

swift基本数据类型的使用的更多相关文章

  1. swift基本数据类型使用

    swift基本数据类型的使用之一: 字符串的使用 swift String的使用 1.字符串的定义 1> 不可变字符串的定义 2> 可变字符串的定义 2.获取字符串的长度 3.字符串的拼接 ...

  2. swift 中数据类型那个的转换

    在swift中关于数据类型的转换,如果参数是可选类型? 那么打印或者转换的结果 会带有Optional 字样,,

  3. iOS开发零基础--Swift篇:Swift中数据类型

    Swift类型的介绍 Swift中的数据类型也有:整型/浮点型/对象类型/结构体类型等等 先了解整型和浮点型 整型 有符号 Int8 : 有符号8位整型 Int16 : 有符号16位整型 Int32 ...

  4. Swift 基本数据类型

    Swift 1,Swift支持所有C和Objective-C的基本类型,支持面向过程和面向对象的编程机制. 2,Swift提供了两种功能强劲的集合类型:数组和字典. 3,元组. 4,可选类型. 5,S ...

  5. Swift - 基本数据类型,及常/变量声明

    2015-01-08 14:59 发布:yuhang 浏览:434 下面是Swift中基本的数据类型介绍说明: 1,变量:使用var声明 1 var str:String = "hangge ...

  6. Swift中数据类型

    Swift类型的介绍 Swift中的数据类型也有:整型/浮点型/对象类型/结构体类型等等 先了解整型和浮点型 整型 有符号 Int8 : 有符号8位整型 Int16 : 有符号16位整型 Int32 ...

  7. Swift 基本数据类型与运算符表达式

    // // main.swift // LessonSwift01 // // Created by lanouhn on 16/1/25. // Copyright © 2016年 齐彦坤. All ...

  8. swift基本数据类型使用-数组使用

    目录 数组的使用 1.数组的定义 2.对可变数组的基本操作 3.数组的遍历 4.数组的合并 5. 示例 数组的使用 1.数组的定义 1> 定义不可变数组 2> 定义可变数组 2.对可变数组 ...

  9. Swift - 复杂数据类型说明(数组,字典,结构体,枚举)

    1,数组 - Array 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 var types ...

随机推荐

  1. Hadoop2.0新特性-持续追加【干货】

    1.NAME NODE HA 2.NAME NODE Federation 3.HDFS 快照(目录快照) 4.HDFS 缓存 5.HDFS ACL 6.异构层级存储结构 -------------- ...

  2. [算法] 插入排序 Insertion Sort

    插入排序(Insertion Sort)是一种简单直观的排序算法.它的工作原理是通过构建有序序列,对于未排序数据,在已排序序列中从后向前扫描,找到相应位置并插入.插入排序在实现上,通常采用in-pla ...

  3. WScript中调用js方法

    http://zhidao.baidu.com/question/484374074.html ———————————————————————————————————————————————— Sub ...

  4. C++中#include包含头文件带 .h 和不带 .h 的区别

    C++中#include包含头文件带 .h 和不带 .h 的区别? 如 #include <iostream> 和 #include <iostream.h> 包含的东西有哪些 ...

  5. 详解Java解析XML的四种方法

    XML现在已经成为一种通用的数据交换格式,它的平台无关性,语言无关性,系统无关性,给数据集成与交互带来了极大的方便.对于XML本身的语法知识与技术细节,需要阅读相关的技术文献,这里面包括的内容有DOM ...

  6. 浅析网站开发中的 meta 标签的作用

    *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !important; } /* ...

  7. PsLookupProcessByProcessId分析

    本文是在讨论枚举进程的时候产生的,枚举进程有很多方法,Ring3就是ZwQuerySystemInformation(),传入SysProcessesAndThreadsInformation这个宏, ...

  8. transition:all 0.5s linear;进度条动画效果 制作原理

    Html: <span class="progress"><b ><i></i></b><em>50< ...

  9. 使用Windbg和SoS扩展调试分析.NET程序

    在博客堂的不是我舍不得 - High CPU in GC(都是+=惹的祸,为啥不用StringBuilder呢?). 不是我舍不得 - .NET里面的Out Of Memory 看到很多人在问如何分析 ...

  10. Spring启动时加载数据

    程序中也许有会有许多常用的,不会经常更改的数据,我们可以在程序初始化的时候就把他们加载,就不用频繁的加载或者查询. 以下是几个常用的,有COPY收集的,也有自己弄. 1. 实现BeanPostProc ...