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 String { | |
func first(_ search: String) -> Int { | |
var hit: Int = -1 | |
next: for i in 0..<(self.characters.count - search.characters.count) { | |
for j in 0..<search.characters.count { | |
let n = self.characters[self.index(self.startIndex, offsetBy: (i+j))] | |
let s = search.characters[search.index(search.startIndex, offsetBy: j)] | |
if n != s { | |
break | |
} else if j == search.characters.count - 1 { |
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 | |
extension Data { | |
func uint16() -> AnySequence<UInt16>? { | |
guard self.count % 2 == 0 | |
else { return nil } | |
return AnySequence<UInt16> { () -> AnyIterator<UInt16> in | |
let size = self.count / 2 | |
var currentIndex = 0 |
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 | |
struct UInt16Sequence: Sequence, IteratorProtocol { | |
var data: Data | |
init?(data: Data) { | |
guard data.count % 2 == 0 | |
else { return nil } | |
self.data = data | |
} |
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 | |
struct Data16: Sequence, IteratorProtocol { | |
let data8: Data | |
init(_ data8: Data) { | |
self.data8 = data8 | |
self.currentIndex = 0 | |
} | |
var currentIndex: Int |
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 Array { | |
/** | |
Create a new array containing the generating element. | |
- parameter generator: The Function to generate element. | |
- parameter count: The number of times to repeat the value passed in the repeatingFunc parameter. | |
*/ | |
init(repeatingFunc generator: () -> Element, count: Int) { | |
self.init() | |
for _ in 0..<count { |
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 | |
let constants = [ | |
NSLocaleIdentifier, | |
NSLocaleLanguageCode, | |
NSLocaleCountryCode, | |
NSLocaleScriptCode, | |
NSLocaleVariantCode, | |
NSLocaleExemplarCharacterSet, | |
NSLocaleCalendar, |
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 | |
/* | |
NSLocaleについて | |
# 特徴 | |
設定できるのが最初の言語と国が指定できるlocaleIdentifierのみ。 | |
出力オンリー。 | |
言語ごとに、文字名を出力させることが出来る。 | |
ex 言語を日本語に設定すると以下の出力は日本語になり、 | |
英語にすると英語で出力される。 |
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 | |
let idts = NSLocale.availableLocaleIdentifiers() | |
print(idts) | |
/* | |
["eu", | |
"hr_BA", | |
"en_CM", | |
"rw_RW", | |
"en_SZ", |
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 | |
let ret = NSNumberFormatter.localizedStringFromNumber(111111111, numberStyle:NSNumberFormatterStyle.SpellOutStyle) | |
print("ret = \(ret)") | |
let nf = NSNumberFormatter() | |
nf.locale = NSLocale(localeIdentifier:"ja_JP") | |
nf.numberStyle = NSNumberFormatterStyle.SpellOutStyle |
NewerOlder