Skip to content

Instantly share code, notes, and snippets.

View toshi0383's full-sized avatar
🏠
Working from home

Toshihiro Suzuki toshi0383

🏠
Working from home
View GitHub Profile
@toshi0383
toshi0383 / CodePiece.m
Created October 27, 2015 14:27
tvOSでWebView動きましたん。 #CodePiece
#import "ViewController.h"
@interface ViewController ()
@property (nonatomic) id webview;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
@toshi0383
toshi0383 / CodePiece.swift
Created October 30, 2015 05:19
functionの引数はコピーで渡されるのかと思ってたけど違った。 #CodePiece
import UIKit
class C {
var view:UIView
init(view:UIView) {
self.view = view
}
}
var v = UIView()
var c = C(view:v)
@toshi0383
toshi0383 / CodePiece.swift
Created November 4, 2015 20:08
YAY #CodePiece
print("installed CodePiece.app via AppStore ! 🎉")
NSLog(@"%s", __FUNCTION__);
UIDeviceOrientation deviceOrientation = [[UIDevice currentDevice]orientation];
UIInterfaceOrientation currentOrientation = [[UIApplication sharedApplication]statusBarOrientation];
NSLog(@"%@", UIDeviceOrientationIsLandscape(deviceOrientation)?@"deviceLand":@"devicePort");
NSLog(@"%@", UIInterfaceOrientationIsLandscape(currentOrientation)?@"currentStatusBarLand":@"currentStatusBarPort");
@toshi0383
toshi0383 / CodePiece.swift
Created November 11, 2015 11:39
先ほどの関数引数のT->SクロージャのTが反変であることのデモコードになります。 #cm_ios9 #CodePiece
func test2(b:(Int) -> Any) {
}
test2 {(a:Int) in
return 0
}
test2 {(a:Any) in // <= does compile
return 0
}
public struct NSTrackingAreaOptions : OptionSetType {
public init(rawValue: UInt)
/* Type of tracking area. You must specify one or more type from this list in the NSTrackingAreaOptions argument of -initWithRect:options:owner:userInfo: */
public static var MouseEnteredAndExited: NSTrackingAreaOptions { get } // owner receives mouseEntered when mouse enters area, and mouseExited when mouse leaves area
public static var MouseMoved: NSTrackingAreaOptions { get } // owner receives mouseMoved while mouse is within area. Note that mouseMoved events do not contain userInfo
public static var CursorUpdate: NSTrackingAreaOptions { get } // owner receives cursorUpdate when mouse enters area. Cursor is set appropriately when mouse exits area
/* When tracking area is active. You must specify one of the following in the NSTrackingAreaOptions argument of -initWithRect:options:owner:userInfo: */
public static var ActiveWhenFirstResponder: NSTrackingAreaOptions { get } // owner receiv
@toshi0383
toshi0383 / CodePiece.swift
Created December 4, 2015 08:22
エラーにならないんだ。。 #CodePiece
func exec(closure:Int->Void) {
closure(4)
}
exec {number in
print(number) // 4
let number = 3
print(number) // 3
}
func fib(idx:Int) {
let result = (0...idx).reduce([Int]()) {(var t, e) in
t.append(t.count < 2 ? e : t[t.count-2] + t[t.count-1])
return t
}.last
print(result ?? "no value found")
}
_ = Process.arguments
.map{Int($0)}.flatMap{$0}.filter{$0>=0}.map(fib)
@toshi0383
toshi0383 / CodePiece.swift
Created December 26, 2015 06:06
Localize日本語だけでいいのならこれで良さげ #cswift #CodePiece
struct Book {
enum BookType: String {
case 単行本, 電子書籍
}
let bookType:BookType
let price:Int
}
print(Book.BookType.単行本) // "単行本"
@toshi0383
toshi0383 / CodePiece.sh
Created December 26, 2015 08:23
shit #cswift #CodePiece
swift $ find . -name "*rst" -print0 | xargs -0 wc -l
37721 total