Skip to content

Instantly share code, notes, and snippets.

View yosshi4486's full-sized avatar

yosshi4486 yosshi4486

View GitHub Profile
@yosshi4486
yosshi4486 / ImageCodeOfCanMove.swift
Created May 2, 2021 03:57
ImageCode of CanMove.
extension Array where Element == List {
    func canMove(into otherContainer: List) -> Bool {
        return allSatisfy({ $0.canMove(into: otherContainer) })
    }
}
@yosshi4486
yosshi4486 / NavigationController+BarAppearance.swift
Last active May 22, 2021 02:29
viewWillAppearでこういうappearance設定を呼んであげると切り替えがうまくいく
extension UINavigationController {
/*
iOS13以降では、利用可能な場合はAppearance系API経由で見た目を設定するようにする。
 視覚情報と情報構造の切り分けを意識する。
*/
/// 不透明のNavigationBarを構成する
func configureOpaqueBar() {
let navBarAppearance = UINavigationBarAppearance()
@yosshi4486
yosshi4486 / ReviewRequestManager.swift
Last active August 26, 2021 19:34
Implementation example of Review Request in iOS.
//
// ReviewRequestManager.swift
//
// Created by yosshi4486 on 2021/07/22.
//
import StoreKit
/// The global variable to get current app version.
///
@yosshi4486
yosshi4486 / StringToImageConvert.swift
Created August 12, 2021 06:50
Convert a string to UIImage by using UIGraphicsImageRenderer.
let string = "🤩"
let bounds = CGRect(x: 0, y: 0, width: 30, height: 30)
let image = UIGraphicsImageRenderer(size: bounds.size).image { context in
let attributes: [NSAttributedString.Key: Any] = [
.font: UIFont.preferredFont(forTextStyle: .body),
.foregroundColor: UIColor.label
]
@yosshi4486
yosshi4486 / SubtitledNavigationTitleView.swift
Created August 30, 2021 01:08
Subtitled navigation title view
class SubtitledNavigationTitleView: UIView {
let titleLabel: UILabel = {
let label = UILabel()
label.adjustsFontForContentSizeCategory = true
label.font = .preferredFont(forTextStyle: .headline)
label.textAlignment = .center
label.numberOfLines = 1
return label
}()
@yosshi4486
yosshi4486 / TwoColumnTextViewController.swift
Created October 4, 2021 04:23
Two Column TextView with TextKit Sample
class ViewController: UIViewController {
var leftTextView: UITextView!
var rightTextView: UITextView!
lazy var textStorage = NSTextStorage(string: """
「ではみなさんは、そういうふうに川だと云いわれたり、乳の流れたあとだと云われたりしていたこのぼんやりと白いものがほんとうは何かご承知ですか。」先生は、黒板に吊つるした大きな黒い星座の図の、上から下へ白くけぶった銀河帯のようなところを指さしながら、みんなに問といをかけました。
 カムパネルラが手をあげました。それから四五人手をあげました。ジョバンニも手をあげようとして、急いでそのままやめました。たしかにあれがみんな星だと、いつか雑誌で読んだのでしたが、このごろはジョバンニはまるで毎日教室でもねむく、本を読むひまも読む本もないので、なんだかどんなこともよくわからないという気持ちがするのでした。
 ところが先生は早くもそれを見附みつけたのでした。
「ジョバンニさん。あなたはわかっているのでしょう。」
@yosshi4486
yosshi4486 / ViewController.swift
Created October 13, 2021 05:36
Learn behaviors of lineFragmentRect and lineFragmentUsedRect
//
// ViewController.swift
// UITextViewPractices
//
// Created by yosshi4486 on 2021/10/13.
//
import UIKit
class ViewController: UIViewController {
@yosshi4486
yosshi4486 / ViewController.swift
Created November 15, 2021 03:28
Creating an own view subclass that can receive keyboard input.
class CustomInputView: UIView, UIKeyInput {
private let label = UILabel()
override init(frame: CGRect) {
super.init(frame: frame)
label.tintColor = .label
label.font = .preferredFont(forTextStyle: .body, compatibleWith: nil)
label.text = ""
@yosshi4486
yosshi4486 / NetworkConnectivityManager.swift
Last active May 9, 2022 00:58
Sample use of NWPathMonitor
/// A class that checks and notifies an internect connectivity changes.
class NetworkConnectivityManager {
/// The static singleton instance. You can use this throught `NetworkConnectivityManager.shared`.
///
/// Creating several manager instances doesn't make sense, so we design it as singleton.
static let shared = NetworkConnectivityManager()
/// The static notification name that the notification is post when a network status change. The object is [NWPath.Status](https://developer.apple.com/documentation/network/nwpath/status)
static let networkConnectivityDidChangeNotificationName = Notification.Name(rawValue: "_networkConnectivityDidChangeNotification")
@yosshi4486
yosshi4486 / SynchronizingKeyValueStore.swift
Last active July 17, 2024 08:38
Example of syncing key value stores.
//
// SynchronizingKeyValueStore.swift
//
// Created by yosshi4486 on 2022/08/30.
//
import Foundation
/// A key value store that stores a key-value into both local and cloud. Subclass this class and override methods for your application.
///