Skip to content

Instantly share code, notes, and snippets.

View fumiyasac's full-sized avatar
🎯
Focusing

Fumiya Sakai fumiyasac

🎯
Focusing
View GitHub Profile
@fumiyasac
fumiyasac / bolt_fundamentals.swift
Created September 9, 2018 10:28
Boltの基本的な使い方
/**
* Alamofireと組み合わせて利用する
*/
// Modelファイル内のメソッド定義
func getDataFromAPI() -> BFTask<AnyObject> {
let taskCompletion = BFTaskCompletionSource<AnyObject>()
let url = "..."
Alamofire.request(url, method: .get)
@fumiyasac
fumiyasac / APIManagerForPickupMessage.swift
Last active November 4, 2018 07:26
ReduxとSwiftの組み合わせを利用したUIサンプル事例紹介 ref: https://qiita.com/fumiyasac@github/items/f25465a955afdcb795a2
import Foundation
import Alamofire
import PromiseKit
import SwiftyJSON
class APIManagerForPickupMessage {
private let baseUrl = "APIのエンドポイントとなるURLを指定する"
// MARK: - Singleton Instance
@fumiyasac
fumiyasac / ArticleViewController.swift
Last active December 3, 2020 16:43
ライブラリなしでメディアアプリでよく見る無限スクロールするタブの動きを実装したUIサンプルの紹介 ref: https://qiita.com/fumiyasac@github/items/af4fed8ea4d0b94e6bc4
class ArticleViewController: UIViewController {
// カテゴリーの一覧データ
private let categoryList: [String] = ArticleMock.getArticleCategories()
// 現在表示しているViewControllerのタグ番号
private var currentCategoryIndex: Int = 0
// ページングして表示させるViewControllerを保持する配列
private var targetViewControllerLists: [UIViewController] = []
@fumiyasac
fumiyasac / FeaturedModel.swift
Last active December 27, 2018 07:16
RxSwiftとUIライブラリの表現を組み合わせたサンプル紹介 ref: https://qiita.com/fumiyasac@github/items/e426d321fbb8ab846bb6
import Foundation
// MEMO: こちらのデータはJSONから生成する
struct FeaturedModel: Decodable {
let id: Int
let title: String
let imageName: String
private enum Keys: String, CodingKey {
@fumiyasac
fumiyasac / AppDelegate.swift
Last active December 29, 2018 04:45
画面のパスコードロック機能を構築する際における実装例とポイントまとめ ref: https://qiita.com/fumiyasac@github/items/6124f9b272f5ee6ebb40
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
・・・(省略)・・・
func applicationDidEnterBackground(_ application: UIApplication) {
print("applicationDidEnterBackground: バックグラウンドへ移行完了した時")
@fumiyasac
fumiyasac / Dependencies.swift
Last active June 17, 2020 13:03
PropertyWrapperを利用したDependendyInjectionの例(定義側)
import Foundation
// MEMO: Swift5.1から登場した「Property Wrappers」を利用したDependency Injectionの実装例
// https://stackoverflow.com/questions/61316547/nested-dependency-injection-through-property-wrapper-crashes
// 補足: Property Wrappersについて
// https://dev.classmethod.jp/articles/property-wrappers/
enum Dependencies {
// MARK: - Struct (for Name of Dependencies)
@fumiyasac
fumiyasac / DependenciesDefinition.swift
Created May 24, 2020 09:13
PropertyWrapperを利用したDependendyInjectionの例(実装側)
// (1) DependenciesDefinition.swift
// それぞれのクラスの依存関係を定義する
import Foundation
final class DependenciesDefinition {
// MARK: - Function
// MEMO: PropertyWrapperを利用したDependencyInjectionを実施する
func inject() {
@fumiyasac
fumiyasac / DependenciesForDomains.swift
Created May 24, 2020 09:32
PropertyWrapperを利用したDependendyInjectionの例(各ドメイン側)
// (1) APIRequestManager.swift
// Infra層部分
import Foundation
import RxSwift
// MARK: - Protocol
protocol APIRequestProtocol {
func getAnnoucements() -> Single<AnnouncementListResponse>
import UIKit
import PlaygroundSupport
protocol WaterfallLayoutDelegate: AnyObject {
    func numberOfColumns() -> Int
    func columnsSize(at indexPath: IndexPath) -> CGSize
    func columnSpace() -> CGFloat
}
final class WaterfallLayoutViewController: UIViewController, UICollectionViewDataSource {
@fumiyasac
fumiyasac / recipe_book_ios14.swift
Created December 23, 2020 14:24
UI実装であると嬉しいレシピブック掲載サンプル変更点(iOS14対応箇所)
// UI実装であると嬉しいレシピブック掲載サンプル変更点(iOS14対応箇所)
// 1. UINavigationController左上にある戻るボタンをロングタップした際に一気に最初の画面に戻る機能への対応
// 本書の中では、UINavigationControllerExtension.swiftに該当箇所があります。
// 戻るボタンの「戻る」テキストを削除した状態にするメソッド
func removeBackButtonText() {
self.navigationController!.navigationBar.tintColor = UIColor(code: "#ffffff")
if #available(iOS 14.0, *) {
self.navigationItem.backButtonDisplayMode = .minimal