Skip to content

Instantly share code, notes, and snippets.

@KentarouKanno
KentarouKanno / dispatch_semaphore_t.m
Last active November 5, 2015 14:18
dispatch_semaphore_t
#import "Connection.h"
#import "Reachability.h"
@implementation Connection {
BOOL b;
}
-(BOOL) connectionStart {
Reachability *reachability = [Reachability reachabilityWithHostName:@"http://www.apple.com"];
@KentarouKanno
KentarouKanno / 乱数 random number.swift
Last active November 7, 2015 23:45
Min値とMax値を指定して乱数を生成
// Min値とMax値を指定して乱数を生成
func generateRandomNumber(var min min: Int, var max: Int) -> Int {
if min > max {
(min, max) = (max, min)
}
return Int(arc4random_uniform(UInt32(max + 1 - min)) + UInt32(min))
}
@KentarouKanno
KentarouKanno / Playground MarkUp
Last active November 8, 2015 03:08
Playground MarkUp
/*:
# **First** Comment
* * *
*Second Comment*
*****
* Item 1
* Item 2
* Item 3
1. Item 1
extension UINavigationController {
override public func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
let bottomLine = CALayer()
bottomLine.frame = CGRectMake(0, self.navigationBar.frame.size.height - 1, self.view.frame.width, 1)
bottomLine.backgroundColor = UIColor.blueColor().CGColor
self.navigationBar.layer.addSublayer(bottomLine)
}
@KentarouKanno
KentarouKanno / RGBA from UIColor.swift
Last active November 9, 2015 21:01
UIColorからRGBAを取得する
var color = UIColor.orangeColor()
var red: CGFloat = 0, green: CGFloat = 0, blue: CGFloat = 0, alpha: CGFloat = 0
let b = color.getRed(&red, green: &green, blue: &blue, alpha: &alpha)
red //=> 1
green //=> 0.5
blue //=> 0
@KentarouKanno
KentarouKanno / AutoLayout + Keyboard ResizeView.swift
Created November 12, 2015 14:42
AutoLayout + Keyboard ResizeView
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var bottomLayout: NSLayoutConstraint!
let notificationCenter = NSNotificationCenter.defaultCenter()
override func viewDidLoad() {
super.viewDidLoad()
@KentarouKanno
KentarouKanno / AutoLayout + Keyboard ResizeView.swift
Created November 12, 2015 14:42
AutoLayout + Keyboard ResizeView
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var bottomLayout: NSLayoutConstraint!
let notificationCenter = NSNotificationCenter.defaultCenter()
override func viewDidLoad() {
super.viewDidLoad()
let array: [String] = []
let array: Array<String> = []
let array = [String]()
if array.count != 0 {
// 配列が存在する時の処理
}
@KentarouKanno
KentarouKanno / 特殊リテラル.swift
Last active November 16, 2015 22:16
Literal Expression
// 現在のファイル名
__FILE__
//=> /Users/******/Desktop/Swift_Practice/Swift_Practice/
// 現在の行数
__LINE__
// 現在のカラム数
__COLUMN__
@KentarouKanno
KentarouKanno / NSRunLoop.swift
Last active November 21, 2015 13:33
NSRunLoop
NSRunLoop.currentRunLoop().addTimer(timerObj, forMode: NSRunLoopCommonModes)