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 Foundation | |
let candidates = ["ガルパン", "は", "いい", "ぞ"] | |
var createdPhrase = [String](count: candidates.count, repeatedValue: "") | |
for i in 0 ..< Int.max { | |
if createdPhrase != candidates { | |
let randomNumber = Int(arc4random_uniform(UInt32(candidates.count))) | |
let nextWord = candidates[randomNumber] | |
print(nextWord) |
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 = [Int](0 ..< 10000) | |
let number = array[1000] // number = 1000 |
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 hexString = "FF" | |
var hex:UInt32 = 0x0 | |
let scanner:NSScanner = NSScanner(string: hexString) | |
scanner.scanHexInt(&hex) | |
print(hex) //255 |
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 | |
protocol TestModelDelegate { | |
func display(something: NSObject) | |
} | |
class TestModel: NSObject { | |
var displayedString: String | |
var delegate: TestModelDelegate? |
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 a = 1 | |
0 ..< 10 ~= a // true |
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 getByteArrayFromImage(imageRef: CGImageRef) -> [UInt8] { | |
let data = CGDataProviderCopyData(CGImageGetDataProvider(imageRef)) | |
let length = CFDataGetLength(data) | |
var rawData = [UInt8](count: length, repeatedValue: 0) | |
CFDataGetBytes(data, CFRange(location: 0, length: length), &rawData) | |
return rawData | |
} |
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 dict = [1: 2, 3: 4] | |
let key = 1 | |
if let value = dict[key] { | |
print(value) | |
} |
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 | |
class CallbackButton: UIButton { | |
private var action: (() -> Void)? | |
init(frame: CGRect, action: (() -> Void)? = nil) { | |
self.action = action |
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 a = 0 | |
switch a { | |
case Int.min ..< 0: | |
print("負数") | |
case 0: | |
print("零") | |
case 1 ... Int.max: | |
print("正数") |
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 ViewController: UIViewController { | |
var settings: UserSettings | |
init() { | |
self.settings = UserSettings(a: 0, b: false, c: "NO") | |
super.init(nibName: nil, bundle: nil) | |
} |