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 / ViewController.swift(NSXMLParser)
Last active November 26, 2015 11:46
Swift2.0でレスポンスのXMLをUITableViewに一覧表示をするサンプル ref: http://qiita.com/fumiyasac@github/items/02a7b962e9a2013c56a0
func parser(parser: NSXMLParser, didEndElement elementName: String, namespaceURI: String?, qualifiedName qName: String?) {
if (elementName as NSString).isEqualToString(self.itemElementName) {
//各メンバ変数がnilでなければメンバ変数elementsへ「キー」と「値」のペアを格納
if !self.name.isEqual(nil) {
self.elements.setObject(self.name, forKey: self.nameElementName)
}
if !self.maker.isEqual(nil) {
@fumiyasac
fumiyasac / ●●●●.swift
Last active December 5, 2015 00:29
Swift2.xでUITextView内のテキストをHTMLとして表示する ref: http://qiita.com/fumiyasac@github/items/40c5250fbed9fe705296
//事前の準備としてtargetTextViewというUITextViewのインスタンスを作成。
//配置したUITextViewのインスタンスに対してリンクを有効にする
self.targetTextView.dataDetectorTypes = .Link
//HTMLタグが混在している文字列に対してHTMLで表示させるようにする処理
//※ "(ダブルクオーテーション)の前に、\(バックスラッシュ)をつけること
do {
//対象のテキスト
@fumiyasac
fumiyasac / AppDelegete.swift
Last active December 30, 2015 01:23
Swift2系でParse.comを利用したサンプルアプリ(Chapter1:導入と疎通の確認まで) ref: http://qiita.com/fumiyasac@github/items/5f0e77728221aade5027
//先頭に追加したフレームワークのクラスをインポート宣言
import Parse
import Bolts
(※途中省略)
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// ----- 追加 ここから↓ -----
// [Optional] Power your app with Local Datastore. For more info, go to
@fumiyasac
fumiyasac / BaseContentsController.swift
Last active October 2, 2016 08:41
iPhoneアプリでUIを作るためのTipsとContainerView・UIPageViewControllerを使ったサンプル紹介 ref: http://qiita.com/fumiyasac@github/items/1244abc8e3286c47ef50
//スクロールが発生した際に行われる処理
func scrollViewDidScroll(scrollview: UIScrollView) {
//コンテンツのスクロールのみ検知
if scrollview.tag == ScrollViewTag.MainScroll.returnValue() {
//現在表示されているページ番号を判別する
let pageWidth: CGFloat = self.mainScrollView.frame.width
let fractionalPage: Double = Double(self.mainScrollView.contentOffset.x / pageWidth)
let page: NSInteger = lround(fractionalPage)
@fumiyasac
fumiyasac / CalculateCalendarLogic.podspec
Last active September 17, 2016 18:19
日本の祝祭日を計算してカレンダ-に表示するアプリサンプル ref: http://qiita.com/fumiyasac@github/items/33bfc07ad36dfffcdf8f
Pod::Spec.new do |s|
s.name = "CalculateCalendarLogic"
s.version = "0.0.2"
s.summary = "This library CalculateCalendarLogic (sample project name is handMadeCalendarAdvance) can judge a holiday in Japan."
s.description = <<-DESC
This library 'CalculateCalendarLogic' can judge a holiday in Japan.
When you use this library, you can judge can judge a holiday in Japan very easily.
A method which named 'judgeJapaneseHoliday' method stores variables year, month, and day in an argument, it returns true or false.
DESC
s.homepage = "http://qiita.com/fumiyasac@github/items/33bfc07ad36dfffcdf8f"
@fumiyasac
fumiyasac / SaveImagetoFirebase.swift
Created November 28, 2016 05:33 — forked from makthrow/SaveImagetoFirebase.swift
saving and getting images in base64 string to Firebase
var data: NSData = NSData()
if let image = photoImageView.image {
data = UIImageJPEGRepresentation(image,0.1)!
}
let base64String = data.base64EncodedStringWithOptions(NSDataBase64EncodingOptions.Encoding64CharacterLineLength)
let user: NSDictionary = ["name":name!,"dob":dateOfBirthTimeInterval, "photoBase64":base64String]
@fumiyasac
fumiyasac / MainContentsCell.swift
Last active December 20, 2016 16:48
FacebookやTwitterのアプリで気になった表現を自分なりにトレースした際の実装ポイントまとめ(タイルレイアウトがサムネイル画像の枚数に応じて変わる表現) ref: http://qiita.com/fumiyasac@github/items/3be1344255b3ebb9f416
//「もっと他の画像を見る」ボタンのアクション
@IBAction func moreImageAction(_ sender: UIButton) {
transitionClosure!(nil)
}
//サムネイル画像のTapGesture発動時に実行されるメソッド
func tapGesture(sender: UITapGestureRecognizer) {
let targetNumber: Int = (sender.view?.tag)!
transitionClosure!(targetNumber)
}
@fumiyasac
fumiyasac / Ramen.swift
Last active March 13, 2019 03:21
RxSwiftでの実装練習の記録ノート(前編:Observerパターンの例とUITableViewの例) ref: https://qiita.com/fumiyasac@github/items/90d1ebaa0cd8c4558d96
import UIKit
import RxDataSources
//ラーメンデータ定義用の構造体(Model層)
struct Ramen {
//取得データに関する定義
let name: String
let taste: String
let imageId: String
@fumiyasac
fumiyasac / Constants.swift
Last active April 12, 2019 06:39
RxSwiftでの実装練習の記録ノート(後編:DriverパターンとAPIへの通信を伴うMVVM構成のサンプル例) ref: https://qiita.com/fumiyasac@github/items/da762ea512484a8291a3
enum APIKey: String {
case foresquare_clientid = "自分のクライアントID"
case foresquare_clientsecret = "自分のシークレット"
}
@fumiyasac
fumiyasac / AddController.swift
Last active October 5, 2017 07:07
ジェスチャーやカスタムトランジションを利用して入力時やコンテンツ表示時に一工夫を加えたUIの実装ポイントまとめ ref: http://qiita.com/fumiyasac@github/items/6c4c2b909a821932be04
//レシピを登録する時のアクション
@IBAction func saveRecipeAction(_ sender: UIButton) {
//キーボードを閉じる
view.endEditing(true)
//ボタンを非活性状態にする
closeButton.isEnabled = false
saveButton.isEnabled = false