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
enum Fruit { | |
case peach | |
case apple | |
case grape | |
} | |
var i = 3 | |
var emptyEnumPtr = withUnsafePointer(to: &i) { UnsafeRawPointer($0) } | |
.bindMemory(to: Fruit.self, capacity: MemoryLayout<Fruit>.size) |
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
enum Fruit { | |
case peach | |
case apple | |
case grape | |
} | |
var fruits: [Fruit] = [] | |
for i in 0..<0xff*MemoryLayout<Fruit>.size { | |
var n = i |
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
protocol EnumExtension {} | |
extension EnumExtension where Self: Hashable { | |
static var all: [Self] { | |
var result: [Self] = [] | |
for i in 0..<0xff*MemoryLayout<Self>.size { | |
var n = i | |
let ptr = withUnsafePointer(to: &n) { UnsafeRawPointer($0) } | |
.bindMemory(to: Self.self, capacity: MemoryLayout<Self>.size) | |
if ptr.pointee.hashValue != n { break } |
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
public var optionalValue:SomeObject! { | |
get { | |
return builderResult.optionalValue | |
} | |
set (value) { | |
builderResult.hasOptionalValue = true //nilの場合でもtrueに | |
builderResult.optionalValue = 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 LinkTextView: UITextView { | |
private var interractDate = Date() | |
var linkTextViewDelegate: LinkTextViewDelegate? | |
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? { | |
interractDate = Date() |
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 ViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
let textView = UITextView(frame: self.view.frame) | |
view.addSubview(textView) | |
let toolBar = UIToolbar(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: 50)) | |
textView.inputAccessoryView = toolBar |
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
extension Router { | |
mutating func registerRouting() { | |
register(routing: TweetRoute.self) { (route: TweetRoute) -> UIViewController in | |
return TweetDetailViewController.ex.make(with: (id: route.id, userName: route.userName)) | |
} | |
} | |
struct TweetRoute: Routing { | |
static var scheme: String { return "https://" } |
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 BasicObject | |
class << self | |
def func(args, &block) | |
method = args[:method] | |
args_map = args[:args] | |
define_method(method) do |args| | |
keys = args_map.values.map { |v| ":#{v}" }.join(',') | |
values = args_map.keys.map { |k| "'#{args[k]}'"}.join(',') | |
s = eval("Struct.new(#{keys}).new(#{values})") | |
s.instance_eval(&block) |
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 foo<T: P>(a: T) -> T.A { | |
fatalError() | |
} | |
struct B {} | |
protocol P {} | |
extension P { | |
typealias A = B | |
} |
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 tru<T1, T2>() -> (T1) -> (T2) -> (T1) { | |
return { t1 in | |
return { t2 in | |
return t1 | |
} | |
} | |
} | |
func fal<T1, T2>() -> (T1) -> (T2) -> (T2) { | |
return { t1 in |