This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let frame1 = CGRect(x: 20, y: 250, width: 157.5, height: 157.5) | |
let view1 = UIView(frame: frame1) | |
let frame2 = CGRect(x: 197.5, y: 250, width: 157.5, height: 157.5) | |
let view2 = UIView(frame: frame2) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let view1 = UIView() | |
view1.backgroundColor = UIColor.systemIndigo | |
view.addSubview(view1) | |
view1.snp.makeConstraints { make in | |
make.top.equalToSuperview().offset(250) | |
make.leading.equalToSuperview().offset(20) | |
make.width.height.equalTo(view.snp.width) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSLayoutConstraint(item: view1, attribute: .leading, | |
relatedBy: .equal, | |
toItem: view, attribute: .leading, | |
multiplier: 1.0, | |
constant: 20).isActive = true | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let view1 = UIView() | |
view1.backgroundColor = UIColor.systemRed | |
view1.translatesAutoresizingMaskIntoConstraints = false | |
view.addSubview(view1) | |
view1.topAnchor.constraint(equalTo: view.topAnchor, | |
constant: 250).isActive = true | |
view1.leadingAnchor.constraint(equalTo: view.leadingAnchor, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
ex.) The following adds an underline attribute to "an example" within "This is an example". | |
let string = NSMutableAttributedString(string: "This is an example.") | |
let underlineAttributes: [NSAttributedStringKey : Any] = [ | |
NSAttributedStringKey.underlineStyle : NSUnderlineStyle.styleSingle.rawValue | |
] | |
string.addAttributeToRange(in: "an example", attributes: underlineAttributes) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// `.` indicates code left out. | |
// Please refer to the sample app for reference | |
// https://github.com/josh-marasigan/ObserverDesignExample | |
class ViewController: UIViewController { | |
. | |
. | |
. | |
// MARK: - Button Configuration | |
private func configChangeBackgroundButtonUI() { | |
. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// `.` indicates code left out. | |
// Please refer to the sample app for reference | |
// https://github.com/josh-marasigan/ObserverDesignExample | |
// Somewhere in the TitleAndTextView.swift file | |
class TitleAndTextView: UIView { | |
. | |
. | |
. | |
// MARK: - Class Properties. Fun fact: emojis are just stirng literals |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct ObserverKeys { | |
static let teal = "observer-example.teal" | |
static let pink = "observer-example.magenta" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Most verbose: No compiler assumptions are made, the closure to map | |
// receives a transforming function explicitly casted as (val: Int) -> Int | |
// Transforms an array of Int and multiplies each value by 10 | |
arrValues.map({ (val: Int) -> Int in | |
return val * 10 | |
}) | |
// Compiler assumes return type for closure, no need to explicitly indicate | |
arrValues.map({ (val: Int) in | |
return val * 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let josh = Son() | |
let joshsMom = Mom(son: josh) | |
joshsMom.tellJoshWhatToDo() | |
--- | |
"Washing Dishes" | |
"Cleaning Room" | |
"Walking Nala" |
NewerOlder