Skip to content

Instantly share code, notes, and snippets.

View ezura's full-sized avatar

Yuka Ezura ezura

View GitHub Profile
@ezura
ezura / CodePiece.swift
Created February 6, 2016 06:41
エラー、出てくれるのね(。 ・ω・)) #CodePiece #cswift
protocol A {
func protocolAFunc ();
}
protocol B {
func protocolBFunc ();
}
struct Sample {
func protocolAFunc() {
@ezura
ezura / CodePiece.swift
Created February 6, 2016 06:43
error: invalid redeclaration of 'protocolFunc()' #CodePiece #cswift
protocol A {
func protocolFunc ();
}
protocol B {
func protocolFunc ();
}
struct Sample {
}
@ezura
ezura / CodePiece.swift
Created February 6, 2016 07:14
優先順位について #CodePiece #cswift
protocol MyProtocol {
func method1() -> String
}
extension MyProtocol {
func method1() -> String {
return "protocol (1)"
}
func method2() -> String {
@ezura
ezura / CodePiece.swift
Created February 13, 2016 12:03
autoclosure の使い所。デバッグのときのみ評価したい場合? #CodePiece #chocoswift
func myDebugPrint(@autoclosure item: () -> String) {
#if DEBUG
print(item())
#endif
}
myDebugPrint("aaa")
@ezura
ezura / CodePiece.swift
Created February 13, 2016 12:07
こっちの方が良い例かも(・ω・)? #CodePiece #chocoswift
func myDebugPrint(@autoclosure item: () -> String) {
#if DEBUG
print(item())
#endif
}
class Sample {
func hoge() -> String {
// 重い処理
return "aaaa"
@ezura
ezura / CodePiece.swift
Created February 13, 2016 12:09
こっちの方が良い例かも(・ω・)? #CodePiece #chocoswift
func myDebugPrint(@autoclosure item: () -> String) {
#if DEBUG
print(item())
#endif
}
class Sample {
func hoge() -> String {
// 重い処理
return "aaaa"
@ezura
ezura / CodePiece.swift
Created February 15, 2016 11:01
自作の構造体で Range までは作れたけど、比較に使おうとするとできない…(´・ω・`)? #CodePiece
struct MyForwardIndexTypeStruct {
var num: Int
init(_ num: Int) {
self.num = num
}
}
// Equatable
func == (lhs: MyForwardIndexTypeStruct, rhs: MyForwardIndexTypeStruct) -> Bool {
return lhs.num == rhs.num
@ezura
ezura / CodePiece.swift
Created February 17, 2016 12:15
これでパターンマッチもできる Range になりました\(^o^)/ #CodePiece
struct MyForwardIndexTypeStruct {
var num: Int
init(_ num: Int) {
self.num = num
}
}
// Equatable
func == (lhs: MyForwardIndexTypeStruct, rhs: MyForwardIndexTypeStruct) -> Bool {
return lhs.num == rhs.num
@ezura
ezura / CodePiece.swift
Created February 18, 2016 04:35
Optional じゃない場合でも中身が nil になってる可能性あるよねって思ったの #CodePiece
class ActionDelegate {
let member = "ActionDelegate"
}
class DelegateSampleClass {
weak var delegate : ActionDelegate!
init (delegate: ActionDelegate) {
self.delegate = delegate
}
func notOptional() {
@ezura
ezura / CodePiece.swift
Created February 22, 2016 12:55
required 不要になるパターンめも #CodePiece
protocol HogeProtocol {
init(name: String)
}
class HogeClass : HogeProtocol {
required init(name: String) { // HogeProtocol の init(name: String) 必須
}
}
class Hige : HogeClass {
required init(name: String) { // HogeProtocol の init(name: String) 必須