Files
SwiftStudy/07 结构体.playground/Contents.swift
2022-01-06 23:03:08 +08:00

59 lines
1.5 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import UIKit
var greeting = "Hello, playground"
//: ###
/**
Swift ,BoolIntDouble StringArrayDictionary
- initializer
-
*/
struct Date {
//
var year: Int
var month: Int
var day: Int
}
//
var date = Date(year: 2021, month: 12, day: 14)
struct Point {
var x: Int = 0
var y: Int
}
var p1 = Point(x: 10, y: 10)
// p2使 Point(y), x
var p2 = Point(y: 10)
//: ####
/*:
-
*/
struct PointA {
var x: Int = 0
var y: Int = 0
init(x: Int, y: Int) {
self.x = x
self.y = y
}
}
// PointA
var p3 = PointA(x: 12, y: 12)
//: ####
struct PointB {
var x: Int = 0 // 8
var y: Int = 0
var origin: Bool = false
}
print(MemoryLayout<PointB>.alignment) // 8
print(MemoryLayout<PointB>.stride) // 24
print(MemoryLayout<PointB>.size) // 17