Skip to content

Instantly share code, notes, and snippets.

View SatoTakeshiX's full-sized avatar

佐藤剛士 SatoTakeshiX

View GitHub Profile
@SatoTakeshiX
SatoTakeshiX / Closure_Sample.swift
Last active January 6, 2016 04:28
swift クロージャーのサンプルコード
//: Playground - noun: a place where people can play
import UIKit
/*
ネスト関数でクロージャーを作る。
*/
func outer() -> () ->Void{
@SatoTakeshiX
SatoTakeshiX / StrongReferenceCycles.swift
Last active January 13, 2016 14:57
【朝活】iOS開発会議 in beez渋谷47回目でのコード
//: Playground - noun: a place where people can play
import UIKit
/*
参照カウンタの仕組み
インスタンスが生成されると1になる。
参照が増えるごとに+1。参照減ると-1。
参照が0になるとインスタンスが破棄される。
*/
@SatoTakeshiX
SatoTakeshiX / Optional_sample.swift
Created January 20, 2016 17:26
オプショナル型のサンプル
//: Playground - noun: a place where people can play
import UIKit
var strs : String? = "SOMESTRING"
print(strs!.lowercaseString)
var a: Int?
//var b: Optional<Int> // Int? と同じ意味
@SatoTakeshiX
SatoTakeshiX / SampleEnum.swift
Created January 27, 2016 22:27
SwiftのEnumサンプル
//: Playground - noun: a place where people can play
import UIKit
enum DeviceType {
case PC
case SmartPhone
case Tablet
}
@SatoTakeshiX
SatoTakeshiX / ClassStructSample.swift
Last active February 3, 2016 15:53
Swifのクラスと構造体サンプル
//: Playground - noun: a place where people can play
import UIKit
/*
関数の定義
*/
//引数をとらない関数
func someFunc(){
print("引数も戻り値もない関数")
@SatoTakeshiX
SatoTakeshiX / SampleProtocol.swift
Created February 17, 2016 15:21
【朝活】iOS開発会議 in beez渋谷50回目 サンプルコード
//: Playground - noun: a place where people can play
import UIKit
/*
プロトコル:実装を伴わない宣言の集合。インターフェース。クラス、構造体、列挙型を定義するとき、プロトコルを指定して、そのプロトコルが宣言しているメソッドなどを宣言。継承できない構造体でも、プロトコルに定義されているインターフェースの実装が保証される。
「用語」
プロトコルを採用する->プロトコルを使ってクラス、構造体、列挙型を定義する
@SatoTakeshiX
SatoTakeshiX / CodePiece.swift
Created September 18, 2016 03:55 — forked from akio0911/CodePiece.swift
パターンマッチの例 #swift2 #CodePiece #swift #swiftlang
enum Gender {
case Male, Female
}
enum TimeSaleResult {
case Normal, Morning, Evening
}
func TimeSale(hour:Int) -> TimeSaleResult {
switch hour {
@SatoTakeshiX
SatoTakeshiX / CodePiece.swift
Created December 3, 2016 10:06
吉川さんにいい感じのSwiftの書き方を教えてもらった。(*´ω`*) #love_swift #CodePiece
//: Playground - noun: a place where people can play
import UIKit
//not good code
var photos: [UIImage] = {
var images = [UIImage]()
for index in 1...8 {
let photoName = "nature" + String(index) + ".jpg"
@SatoTakeshiX
SatoTakeshiX / CodePiece.swift
Created December 7, 2016 01:55
UIImageViewの画像を無理やり色を変える方法。これを使えばデザイナーに頼まなくても色変更可能 #CodePiece
@IBOutlet weak var imageView: UIImageView! {
didSet {
imageView.image = UIImage.init(named: "photo1")?.withRenderingMode(.alwaysTemplate)
imageView.tintColor = UIColor.white
}
}
@SatoTakeshiX
SatoTakeshiX / file0.txt
Created January 13, 2017 14:10
cocoapodがおかしくなった時に行うこと ref: http://qiita.com/SatoTakeshiX/items/02d56d269778c9bb3f19
rm -rf ~/Library/Caches/CocoaPods
rm -rf Pods
rm -rf ~/Library/Developer/Xcode/DerivedData
pod install