swift データ型

let i: Int = 10
let d = 53.8 // doubleになる

let s = "string"
let flag = true // bool true/false

var x = "five"
x = String(5)
print(x)

バックスラッシュはoption + ¥

// 数値
// + - * / %
// print(10 / 3)
// print(10.0 / 3)

var y = 10
y *= 10

print("hello" + " world!")
print("y is \(y - 5)")

&& || !

let score = 82
let result: String

if score > 80 {
    result = "great"
} else if score > 60{
  result = "good"  
} else {
    result = "so so..."
}

print(result)

条件演算子

result = score > 80 ? "great" : "soso.."
print(result)

case

let num = 4

switch num {
    case 0:
        print("zero")
    case 1, 2, 3:
        print("small")
    case 4..6:
        print("4/5/6")
    case 7..<9:
        print("7/8")
    case let n where n > 20:
        print("\(n) is huge!")
    default:
        print("n.a.")
}

swift playground

セミコロンはありません。

print("Hello World!")

Hello World!

自動的に改行されます。

print("Hello World!")
print("Hello")

定数、変数

let msg1: String
msg1 = "this is let"

print(msg1)

var msg2: String
msg2 = "this is variable"
msg2 = "oh, this is swift variable"
print(msg2)

this is let
oh, this is swift variable
なるほど!

iosでヤフオクのlayoutを作ろう

topのview controller
まずは、constraintをつけない状態です。まるっきりwire frameですね。

constraintをつけます。なんだろう、area6のmargin-rightがおかしい。

Trailing space to: superview Equals:5 はArea2, Area4と一緒なのに。。。
イライラしてきた。先に進もう。

constraintをつけていく

全ての制約を削除するのは下のclear constraints

control dragで制約をつけることも可能

インスペクターペインでconstraintを確認することも可能

equal height

なるほど

Equal Hights Constraintで高さの比率を1:2、2:1などに出来る

viewのlayoutの名称をつけていく

なるほど!!

tapすると日付を表示する

@IBAction func changeLabel(sender: AnyObject) {
        var date:NSDate = NSDate();
        let format = NSDateFormatter()
        format.dateFormat = "yyyy-MM-dd HH:mm:ss"
        myLabel.text = format.stringFromDate(date)
    }

うーむ、mac買い換えて〜

調子に乗って、一週間後を表示

@IBAction func changeLabel(sender: AnyObject) {
        let now = NSDate()
        var date1:NSDate = NSDate(timeInterval: 60*60*24*7, sinceDate: now);
        let format = NSDateFormatter()
        format.dateFormat = "yyyy-MM-dd HH:mm:ss"
        myLabel.text = format.stringFromDate(date1)
    }

はいはいはい、なるほど!

一分前なら、マイナスにすればOKですね。

var date1:NSDate = NSDate(timeInterval: -60, sinceDate: now);

preview -> mainstoryboardでプレビューが観れる

swiftでテキストを変更する

class ViewController: UIViewController {
    
    
    @IBOutlet weak var myLabel: UILabel!
    @IBAction func changeLabel(sender: AnyObject) {
        myLabel.text = "you changed me"
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

ああああ、mac買い換えて〜
誰か譲ってくれないかな

strtotime

echo date("Y/m/d h:i:s");
echo "<br>";
echo date("Y/m/d h:i:s", strtotime(" - 2 sec"));

echo "<br>";
echo "<br>";
$date = "2018/05/20 12:30:00";
echo date("Y/m/d h:i:s", strtotime("$date -1 day"));
echo "<br>";
echo date("Y/m/d h:i:s", strtotime("$date -10 sec"));