This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 今回は、StringLiteralTypeは、String型でしか使用しないため独自Protocolを定義 | |
protocol CustomExpressibleByStringLiteral: ExpressibleByStringLiteral where StringLiteralType == String { | |
init(stringLiteral value: Self.StringLiteralType) | |
} | |
// UserのIdを表す型 | |
struct UserId { | |
let value: String | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let array = [0, 2, 0, 2, 2, 1, 2, 2] | |
// flatMap({$0})を入れないと、コンパイルエラー | |
// AnySequenceとArrayで同じprefix()メソッドがあり、どちらを使用するのかが曖昧のため、コンパイルエラーになる | |
let map = array.prefix(while: {$0 != 1}).flatMap({$0}).filter( {$0 == 2} ) | |
print(map) // [2, 2, 2] | |
// filterの中で何かして、結果に反映するかの判断するには、このようにすることができる | |
// つまり、continueを使用していたところは、return falseにすることができる | |
let map = array.prefix(while: {$0 != 1}).flatMap({$0}).filter( { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func logA(tag: String, param: [String: String]) { | |
print("\(tag) : \(param)") | |
} | |
func logB(tag: String) { | |
print("\(tag) : param なし") | |
} | |
func main0(param: [String: String]?, id: String?) { | |
if var param = param { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// When property name and key are different | |
let data = """ | |
{ | |
"user_id":0, | |
"user_name": "name", | |
"mail-address": "address" | |
} | |
""".data(using: .utf8)! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TodoList { | |
var list = Array<String>() | |
func isEmpty() -> Bool { | |
return list.count == 0 | |
} | |
func append(_ todo: String) { | |
list.append(todo) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Entity { | |
let name: String | |
let age: Int | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <UIKit/UIKit.h> | |
@interface SnsPostViewController : UIViewController | |
+ (void)showActionSheet:(UIViewController*)vc ActivityItems:(NSArray*)activityItems; | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (id)getUserDefaultsWithKey:(NSString*)key { | |
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; | |
id value = [ud boolForKey:key]; | |
return value; | |
} |