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
// We make our Property Wrapper Generic. | |
@propertyWrapper | |
struct Store<T> { | |
// This is the key that user can provide | |
var key: String | |
// The default value for the property | |
var defaultValue: T | |
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
@propertyWrapper | |
struct Store { | |
// Key for UserDefaults | |
var key: String | |
// This is the special variable required in Property Wrapper. | |
var wrappedValue: Bool { | |
set { UserDefaults.standard.set(newValue, forKey: key) } | |
get { UserDefaults.standard.value(forKey: key) as? Bool ?? false } |
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 AppSettings { | |
// Update the respective value in UserDefault | |
static var isDarkModeEnabled = false { | |
didSet { | |
UserDefaults.standard.setValue(isDarkModeEnabled, forKey: "is_dark_mode_enabled") | |
} | |
} | |
} |
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
class SecondViewController: UIViewController { | |
var someText = "" | |
var controller: UIAlertController! | |
var label = UILabel() | |
override func loadView() { | |
view = UIView() | |
view.backgroundColor = .white |
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
extension UIView { | |
func shake() { | |
let animation = CAKeyframeAnimation() | |
animation.keyPath = "position.x" | |
animation.values = [0, 10, -10, 10, -5, 5, -5, 0 ] | |
animation.keyTimes = [0, 0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875, 1] | |
animation.duration = 0.4 | |
animation.isAdditive = 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
// DRAFT:- | |
1. Give scrollview with top, leading, trailing & bottom constraint | |
2. Give the container view inside scrollview with | |
- Center x to scrollview | |
- Center y to scrollview | |
- trailing to scrollview | |
- bottom to scrollview | |
- Equal Height to scrollview | |
- Equal Width to scrollview |
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
1. Content Hugging Property: | |
- This priority defines whether the content size should increase beyond its intrinsic size. | |
- Content Hugging :: Content doesnot want to grow. | |
Horizontal Hugging: Higher priority means that content width doesnot want to grow beyond its intrinsic width. | |
Vertical Hugging: Higher priority means that content height doesnot want to grow beyond its intrinsic height. | |
2. Content Compression Resistance | |
- This priority defines whether the content size should decrease beyond its intrinsic size. | |
- Content Compression Resistance :: Content doesnot want to shrink |
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
1. Duplicate Build Configurations from Project Settings | |
- Example: Duplicate debug & name it as debugDev. Duplicate release & name it as releaseDev. | |
2. Change Project's bundle identifier from Target Build Settings | |
- Change it to reflect build configurations | |
3. Create User Defined Settings | |
- There is + sign on navigation bar in Build Settings. Click on it & create User Defined Settings as needed | |
- Example: If you need different names on different builds, add setting name APP_DISPLAY_NAME & so on. | |
- You need to use this created settings on info.plist file. Eg, Change Bundle Display Name value to $(APP_DISPLAY_NAME). |
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
Steps for creating custom UIView. | |
1. Create a xib file, eg: MyCustomView.xib | |
2. Do necessary layout in xib file | |
3. Create a UIView file. eg: MyCustomView.swift. | |
4. Set this MyCustomView.swift file as the file owner of that xib | |
5. Create necessary outlets from the .xib file to .swift file. Important: Create one outlet for the root parent UIView to .swift file. | |
Name this outlet as as containerView | |
6. Override both the init method i.e using decoder & frame | |
7. Set the code as follows |
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
class func from(r:CGFloat,g:CGFloat,b:CGFloat,a:CGFloat) -> UIColor { | |
return UIColor(red: r/255.0, green: g/255.0, blue: b/255.0, alpha: a) | |
} | |
// Hex should be in format #bcbcbc | |
class func from (hex:String) -> UIColor { | |
var cString:String = hex.trimmingCharacters(in: .whitespacesAndNewlines).uppercased() | |
if (cString.hasPrefix("#")) { |
NewerOlder