//
// main.swift
// classTest
//
// Created by 小强 on 15/12/8.
// Copyright © 2015年 小强. All rights reserved.
//
import Foundation
var x = 0.0, y = 0.0, z = 0.0
let possibleNumber = "123";
let convertedNumber = Int(possibleNumber);
print(possibleNumber);
print(convertedNumber);
if (convertedNumber != nil)
{
print("\(possibleNumber) has an integer value of \(convertedNumber!)");
}
else
{
print("\(possibleNumber) could not be converted to an integer");
}
//if let actualNumber = Int(possibleNumber)
//{
// print("\(possibleNumber) has an integer value of \(actualNumber).");
//}
//else
//{
// print("\(possibleNumber) could not be converted to an integer.");
//}
let possibleString: String? = "An optional string.";
print(possibleString!);
let assumeString: String! = "An implicitly unwrapped optional string.";
print(assumeString);
let age = 3;
assert(age > 0, "A person's age cannot be less than zero");
let name = "world";
if name == "world" {
print("hello, world")
} else {
print("对不起,\(name),我不认识你!")
}
name == "world" ? print("hello world") : print("对不起,\(name),我不认识你");
for index in 1 ..< 5
{
print("\(index) * 5 = \(index * 5)");
}
var string:Array = ["D", "o", "g", "!"];
for character in string{
print(character);
}
print("count of string is " + "\(string.count)");
print("capacity of string is " + String(string.capacity));
let normal = "Could you help me,please?";
let shouty = normal.uppercaseString;
print(shouty);
let whispered = normal.lowercaseString;
print(whispered);
//let dogString = "Dog!???";
//for codeUnit in dogString.unicodeScalars
//{
// print("\(codeUnit.value)");
//}
var shoppingList: [String] = ["eggs", "Milk"]
if shoppingList.isEmpty {
print("The shopping list is empty.");
} else {
print("The shopping list is not empty.")
}
shoppingList.append("Flour");
shoppingList += ["Baking Powder"]
print(shoppingList);
var firstItem = shoppingList[0];
print(firstItem);
shoppingList[0] = "Six eggs";
print(shoppingList);
//shoppingList[4..<6 ] = ["Bananas", "Apples"];
shoppingList.insert("Maple Syrup", atIndex: 0);
print(shoppingList);
let mapleSyrup = shoppingList.removeAtIndex(0);
print(mapleSyrup);
print(shoppingList);
for (index, value) in shoppingList.enumerate(){
print("Item \(index + 1): \(value)")
}
var someInt = [Int]();
print("someInts is of type Int[] with \(someInt.count) items. ");
var threeDoubles = [Double](count: 3, repeatedValue: 0.0);
print(threeDoubles);
var anotherThreeDoubles = Array(count: 3, repeatedValue: 2.5);
print("anotherThreeDoubles = \(anotherThreeDoubles)");
var sixDoubles = threeDoubles + anotherThreeDoubles;
print("The sixDoubles is \(sixDoubles)");