Skip to content

Instantly share code, notes, and snippets.

View d-date's full-sized avatar
🏠
Working from home

Daiki Matsudate d-date

🏠
Working from home
View GitHub Profile
import Foundation
import AVFoundation
public enum AVMetadataObjectType {
case UPCECode
case Code39Code
case Code39Mod43Code
case EAN13Code
case EAN8Code
case Code93Code

より良くするために考えたいのが、 これだと

case .division:
  if secondValue != 0 {
    value = firstValue / secondValue
  }
@d-date
d-date / StringToInt.md
Last active February 9, 2017 00:49
StringをIntに変換

お題

StringをIntに変換するとき、どう書いたらスマートなんでしょうね。 例えば、ある本の最初のサンプルアプリで、初心者向けに説明するときはこんな感じ。 電卓のような、ボタンに1~9の文字がセットされていて、それをIntに変換するときの処理。

func stringToInt(_ string: String) -> Int {
 var value: Int = 0
import UIKit
//でもこれだと、styleの指定ができないので、3つのタプルにしてみた
private func showAlert(title: String, message: String, actions: [(String, UIAlertActionStyle, ((UIAlertAction) -> Void)?)]) {
let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
actions.forEach {
let action = UIAlertAction(title: $0, style: $1, handler: $2)
alertController.addAction(action)
}
@d-date
d-date / test.md
Last active February 23, 2017 16:38
{
  "data" : {
     "param" : "hoge"
  }
}
{
//見た目は同じInitializer。単数か複数かは気にする必要なし。勝手にsingleかmultipleに振り分けてくれる。
enum PossibleArrayType<T> {
case single(T)
case multiple([T])
init(_ single: T) {
self = .single(single)
}
init(_ multiple([T]) {
enum Sometype<T: SomeProtocol> {
case one
case two
case three
associatedtype Associated {
switch {
case .one: return One.self
case .two: return Two.self
protocol HogeType {
init(value: String)
}
final class HogeClass { //finalにしておけば
var value = ""
var value2 = ""
required public init(value: String, value2: String) {
self.value = value
@d-date
d-date / FA.swift
Last active March 20, 2017 05:29
Example of using Firebase analytics
import Foundation
import Firebase
typealias FIRParamters = [String : NSObject]
protocol EventReportType {
var name: String { get }
var parameters: FIRParamters? { get }
func sendLog()
}
@d-date
d-date / CodePiece.swift
Created May 1, 2017 11:24
ここでInteger使うと言う発想は話ながら完全に振ってきたやつでした。普段こんなの思いつかない笑 #CodePiece #minna_de_swift
func repeated<T:Integer>(word: String, count: T) -> String {
guard count >= 0 else {
return ""
}
return String(repeating: word, count: Int(count.toIntMax()))
}
repeated(word: "🐬", count: 5)