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 View { | |
func hostingView() -> UIView { | |
let hostingView = UIHostingController(rootView: self) | |
return hostingView.view | |
} | |
} |
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
enum OpenURL { | |
enum Scheme { | |
case url(String) | |
case tel(String) | |
case app(String) | |
} | |
static func open(scheme: OpenURL.Scheme, completion: ((Bool) -> Void)? = nil) { | |
let application = UIApplication.shared | |
let url: URL |
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 SwipeBackGestureViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
navigationController?.hidesBarsOnSwipe = true | |
navigationController?.interactivePopGestureRecognizer?.delegate = self | |
} | |
override func viewDidAppear(_ animated: Bool) { |
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. Using Markup | |
Single Line comment | |
//: line of markup content | |
Multi Line Comment | |
/*: | |
... | |
*/ | |
2. Headings |
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
import Foundation | |
enum Dough: String { | |
case basic | |
case cheeseCrust | |
} | |
enum Topping: String, CaseIterable { | |
case pepperoni | |
case sausage |
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
import UIKit | |
protocol Moveable { | |
func move(to point: CGPoint) | |
} | |
extension Moveable { | |
func move(to point: CGPoint = .zero) { | |
move(to: point) | |
} |
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
func collectionView(_ collectionView: UICollectionView, willDisplaySupplementaryView view: UICollectionReusableView, forElementKind elementKind: String, at indexPath: IndexPath) { | |
// works from iOS 12 and below | |
view.layer.zPosition = 0 | |
} |
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
import Foundation | |
extension String { | |
func toDate(format: String) -> Date? { | |
let formatter = DateFormatter() | |
formatter.dateFormat = format | |
return formatter.date(from: self) | |
} | |
} |
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
/* | |
Filter | |
*/ | |
let familyNames = ["Park", "Lee", "Jong", "Kim", "Choi"] | |
let longFamilyNames = familyNames.filter { $0.count > 3 } | |
print(longFamilyNames) | |
// ["Park", "Jong", "Choi"] | |
let familyNames = ["Park", "Lee", "Jong", "Kim", "Choi"] |
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
import UIKit | |
enum UIHelper { | |
/// Convert Zeplin line height to iOS line spacing | |
static func lineSpacing(from lineHeight: CGFloat, font: UIFont) -> CGFloat { | |
let value = lineHeight - font.lineHeight | |
return value | |
} |
NewerOlder