Skip to content

Instantly share code, notes, and snippets.

@yHomework
yHomework / RoundedLabel.swift
Last active August 5, 2019 10:22
IBDesignable UILabel with rounded corners and paddings
import UIKit
@IBDesignable
class RoundedLabel: UILabel {
var edgeInsets: UIEdgeInsets {
if autoPadding {
if cornerRadius == 0 {
return UIEdgeInsets.zero
} else {
@yHomework
yHomework / AsynchronousOperation.swift
Created August 5, 2019 11:27 — forked from calebd/AsynchronousOperation.swift
Concurrent NSOperation in Swift
import Foundation
/// An abstract class that makes building simple asynchronous operations easy.
/// Subclasses must implement `execute()` to perform any work and call
/// `finish()` when they are done. All `NSOperation` work will be handled
/// automatically.
open class AsynchronousOperation: Operation {
// MARK: - Properties
@yHomework
yHomework / SwiftUI_1.swift
Last active January 4, 2020 20:29
SwiftUI homewor
import SwiftUI
struct ContentView: View {
var body: some View {
GeometryReader { geometry in
ZStack {
Rectangle()
.fill(Color.yellow)
CircleView()
VerticalSquareView()
final class ViewController: UIViewController {
@IBOutlet weak var bottomConstraint: NSLayoutConstraint!
private let disposeBag = DisposeBag()
override func viewDidLoad() {
super.viewDidLoad()
// avoid keyboard.
// The MIT License (MIT)
//
// Copyright (c) 2017 Alexander Grebenyuk (github.com/kean).
import Foundation
import Alamofire
import RxSwift
import RxCocoa
@yHomework
yHomework / ChatCollectionViewFlowLayout.swift
Created March 7, 2020 09:53 — forked from jochenschoellig/ChatCollectionViewFlowLayout.swift
A subclass of UICollectionViewFlowLayout to get chat behavior without turning collection view upside-down. This layout is written in Swift 3 and absolutely usable with RxSwift and RxDataSources because UI is completely separated from any logic or binding.
import UIKit
class ChatCollectionViewFlowLayout: UICollectionViewFlowLayout {
private var topMostVisibleItem = Int.max
private var bottomMostVisibleItem = -Int.max
private var offset: CGFloat = 0.0
private var visibleAttributes: [UICollectionViewLayoutAttributes]?
struct SearchView: View {
@ObservedObject var viewModel: SearchViewModel
var body: some View {
VStack {
TextField("Search", text: $viewModel.query)
List(viewModel.songs) {
Text($0.name)
}
}
@yHomework
yHomework / List.swift
Created March 7, 2020 10:01 — forked from kean/List.swift
Proof-of-concept List as Swift Enum
// The MIT License (MIT)
//
// Copyright (c) 2017 Alexander Grebenyuk (github.com/kean).
import Foundation
/// Proof-of-concept List implementation, not optimized in any way.
///
/// Usage:
///
//
// PaginationNetworkLogic.swift
//
// Created by Daniel Tartaglia on 4/9/17.
// Copyright © 2019 Daniel Tartaglia. MIT License
//
import RxSwift
struct PaginationUISource {
@yHomework
yHomework / DeviceCheck.swift
Created March 7, 2020 15:10 — forked from schirrmacher/DeviceCheck.swift
DeviceCheck Example Implementation for Validating Device Authenticity on iOS
import Foundation
import RxSwift
#if !os(watchOS) && !os(tvOS)
import DeviceCheck
#endif
public struct Client {
private static func retrieveDeviceToken() -> Observable<String?> {