Skip to content

Instantly share code, notes, and snippets.

View tomkowz's full-sized avatar

Tomasz Szulc tomkowz

View GitHub Profile
let views = ["v1": v1, "super": self.view]
self.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:[super]-(<=0)-[v1(50)]", options: .AlignAllCenterY, metrics: nil, views: views))
self.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:[super]-(<=0)-[v1(100)]", options: .AlignAllCenterX, metrics: nil, views: views))
class LetItGoTableViewController: UITableViewController {
private enum SignInField: Int {
case Username
case Password
case RememberMe
case SignInButton
}
// MARK: - Table view data source
@tomkowz
tomkowz / custom-stirng-convertible.swift
Last active January 19, 2018 10:20
CustomStringConvertible
struct Position {
var x: Int = 0
var y: Int = 0
func string() -> String {
return "(\(x), \(y))"
}
}
// CustomStringConvertible provides "description" property.
@tomkowz
tomkowz / string-enum-xcode-7-beta-3.swift
Last active August 29, 2015 14:25
String Enum in Xcode 7 beta 3
enum GameState {
case NotStarted
case InPlay
case GameWon
case PlayingForHigherScores
case GameLost
func simpleDescription(state: GameState) -> String {
switch state {
case .NotStarted:
//
// main.cpp
// ctci-3-3
//
// Created by Tomasz Szulc on 14/07/15.
// Copyright (c) 2015 Tomasz Szulc. All rights reserved.
//
#include <iostream>
class MessageControl: UIView {
@IBOutlet weak var textField: UITextField!
@IBOutlet weak var actionButton: UIButton!
override func awakeFromNib() {
super.awakeFromNib()
self.actionButton.enabled = false
}
override func awakeAfterUsingCoder(aDecoder: NSCoder) -> AnyObject? {
if self.subviews.count == 0 {
let nib = UINib(nibName: "MessageControl", bundle: nil)
let view = nib.instantiateWithOwner(nil, options: nil).first! as MessageControl
view.setTranslatesAutoresizingMaskIntoConstraints(false)
return view
}
return self
}
class ViewController: UIViewController {
/// outlet for the control may be here if used
}
class ViewController: UIViewController {
@IBOutlet weak var textField: UITextField!
@IBOutlet weak var actionButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
self.actionButton.enabled = false
}
@IBAction func onActionPressed(sender: AnyObject) {
enum SegueIdentifier: String {
case ToRed = "Red"
case ToGreen = "Green"
case ToBlue = "Blue"
init?(_ rawValue: String?) {
let out = SegueIdentifier(rawValue: rawValue ?? "")
if rawValue != nil && out != nil {
self = out!
} else {