Skip to content

Instantly share code, notes, and snippets.

@showcove
Created January 8, 2022 04:25
Show Gist options
  • Save showcove/7325890928482254a782fc78bf5687b2 to your computer and use it in GitHub Desktop.
Save showcove/7325890928482254a782fc78bf5687b2 to your computer and use it in GitHub Desktop.
StructVsClass - SubViewController1
//
// SubViewController1.swift
// ClassInStructLifeCycle
//
// Created by jay on 2022/01/08.
//
import UIKit
class SubViewController1: UIViewController {
var model: Model = Model()
override func viewDidLoad() {
super.viewDidLoad()
makeView()
}
@objc func pushSubVC2() {
var passedModel = model // assign struct into another variable
passedModel.name = "passedModel" // edit property in struct for copy trigger
print("---------------------------------------")
print("model is different from passedModel")
print("model : ", model)
print("passedModel : ", passedModel)
print("---------------------------------------\n\n")
let subVC2 = SubViewController2(model: passedModel)
self.navigationController?.pushViewController(subVC2, animated: true)
}
// MARK: - Below is not importatnt!!!!!
func makeView() {
self.title = String(describing: Self.self)
self.view.backgroundColor = .white
makeButton()
}
func makeButton() {
let button: UIButton = UIButton(type: .system)
button.frame = CGRect(x: 0, y: 0, width: 200, height: 100)
button.setTitleColor(.brown, for: .normal)
button.titleLabel?.font = UIFont.systemFont(ofSize: 25, weight: .bold)
button.addTarget(self, action: #selector(pushSubVC2), for: .touchUpInside)
button.setTitle("Push SubVC-(2)", for: .normal)
self.view.addSubview(button)
button.center = view.center
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment