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 / 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 / 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 / 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 / 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 / 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 / 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 / alamofire_fundamentals.swift
Last active September 9, 2018 10:30
Alamofireの基本的な処理について
// その1: APIサーバーとの通信処理(JSONレスポンス取得)
/**
* APIへの通信処理:
* method: .get または .post
* parameters: [String : Any] 例. ["key" : value]
* encoding: JSONEncoding.default (パラメーターがない場合は不要)
* headers: [String : Any] 例. ["key" : value] (認可等が必要なユーザーのデータへアクセスしたい場合は必要)
*/
@fumiyasac
fumiyasac / App.js
Last active January 22, 2019 05:03
ReactNative+Redux+NativeBaseでつくるサンプル実装をのぞく ref: https://qiita.com/fumiyasac@github/items/e27a5901dde1dbcb2086
import React, { Component } from 'react';
// React-Reduxのインポート宣言 → ProviderタグでラップすることでReactコンポーネント内でStoreにアクセスできるようにする
import { Provider } from 'react-redux';
// createStore, applyMiddlewareのインポート宣言
import { createStore, applyMiddleware } from 'redux';
// redux-thunkのインポート宣言
import ReduxThunk from 'redux-thunk';
@fumiyasac
fumiyasac / gist:412e4f1eab0537d20e94cc129dfd5be4
Last active July 21, 2018 09:16
NewYorkTimesのAPIから記事情報を取得する with PromiseKit
import Foundation
import Alamofire
import PromiseKit
import SwiftyJSON
class APIManagerForNewYorkTimes {
private let baseUrl = "https://api.nytimes.com/svc/search/v2/articlesearch.json"
private let key = Constants.NEWYORKTIMES_API_KEY
@fumiyasac
fumiyasac / APIConstant.swift
Last active January 12, 2019 09:44
Tinder風なUIを実装する際のアイデアと実装例紹介 ref: https://qiita.com/fumiyasac@github/items/c68b7ce812bf3ef48a67
// 楽天レシピ別カテゴリランキングのAPIキー ※各自取得をお願いします。
static let API_KEY_RAKUTEN_RECIPE_RANKING = ""