This file contains 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 Foundation | |
/* | |
https://developer.apple.com/library/content/documentation/LanguagesUtilities/Conceptual/iTunesConnect_Guide/Chapters/AppStoreTerritories.html | |
*/ | |
public enum Country: String { | |
case unitedArabEmirates = "ae" | |
case antiguaAndBarbuda = "ag" | |
case anguilla = "ai" | |
case albania = "al" |
This file contains 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
//: Playground - noun: a place where people can play | |
import UIKit | |
struct URLCodableTest: Codable { | |
let ou: URL? | |
let u: URL | |
enum CodingKeys: String, CodingKey { | |
case ou |
This file contains 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
var result: [(hasSmile: Bool, leftEyeClosed: Bool, rightEyeClosed: Bool)] = [] | |
for feature in features as! [CIFaceFeature] { | |
result.append((feature.hasSmile, feature.leftEyeClosed, feature.rightEyeClosed)) | |
} | |
if result.count >= 1 { | |
if result[0].hasSmile { | |
self.playerAttack() |
This file contains 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
// | |
// RootViewController.swift | |
// iOS9Sampler | |
// | |
// Created by Shuichi Tsutsumi on 2015/06/10. | |
// Copyright © 2015 Shuichi Tsutsumi. All rights reserved. | |
// | |
import UIKit |
This file contains 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
extension Double : ForwardIndexType { | |
public func successor() -> Double { | |
return self + 1.0 | |
} | |
} | |
infix operator ∫ { associativity left precedence 120 } | |
func ∫ (left: Range<Double>, right: (Double -> Double)) -> Double { | |
let dx = (left.endIndex - left.startIndex) / 1000 | |
let r = left.startIndex.stride(to: left.endIndex, by: dx) |
This file contains 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 start = NSDate() | |
// someMethod | |
let timeElapsed = -startTime.timeIntervalSinceNow | |
print(timeElapsed) |
This file contains 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 romanStrs = ["M", "D", "C", "L", "X", "V", "I"] | |
let romanNums = [1000, 500, 100, 50, 10, 5, 1] | |
let romanToNum = zip(romanStrs, romanNums).reduce([String: Int]()) { (dic, t) in | |
var dic = dic | |
dic[t.1] = t.0 | |
return dic | |
} |
This file contains 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
[1, 2, 3, 4] -> ["0:1", "1:2", "2:3", "3:4"] |
This file contains 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 numList = [5, 8, 4, 2].map { String(Double($0)) } // 割り算を正確に行うためにDouble型への変換をはさむ | |
print(numList) | |
// ["5.0", "8.0", "4.0", "2.0"] | |
let opeList = ["+", "/", "-"] | |
let zipped = zip(numList, opeList + [""]) | |
let equation = zipped.reduce("") { $0 + $1.0 + $1.1 } | |
print(equation) |
This file contains 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 num = 1234 | |
// Int -> [String] | |
let numList = String(num).characters.flatMap { String($0) } | |
print(numList) | |
// ["1", "2", "3", "4"] | |
let opeList = ["+", "-", "*"] | |
let zipped = zip(numList, opeList + [""]) // 要素数を合わせる |
NewerOlder