Skip to content

Instantly share code, notes, and snippets.

View konrad1977's full-sized avatar

Mikael Konradsson konrad1977

View GitHub Profile
@konrad1977
konrad1977 / ThemeBuilder
Created June 24, 2014 09:32
Simple example of using Builder pattern in Objective-C
//header file
typedef void (^ColorThemeBuilder)(id<ColorThemeProtocol> colorTheme);
@interface ThemeBuilder : NSObject <ColorThemeProtocol>
- (instancetype)initColorTheme:(ColorThemeBuilder)builder;
@end
//Implementation
@konrad1977
konrad1977 / gist:36999217bf4055071d2a
Created October 20, 2014 17:04
Simple a person
class Person {
var firstname: String
var lastname: String
init(firstname: String, lastname: String) {
self.firstname = firstname
self.lastname = lastname
}
}
class Person {
var firstname: String
var lastname: String
func fullname() -> String {
return firstname + " " + lastname
}
init(firstname: String, lastname: String) {
self.firstname = firstname
@konrad1977
konrad1977 / personv3.swift
Last active August 29, 2015 14:07
Person V3
class Person {
var firstname: String
var lastname: String
init(firstname: String, lastname: String) {
self.firstname = firstname
self.lastname = lastname
}
}
@konrad1977
konrad1977 / Person_v4.swift
Last active April 14, 2016 19:20
Person with Protocol
protocol AgeClasificationProtocol {
var age: Int { get }
func agetype() -> String
}
class Person {
let firstname: String
let lastname: String
var age: Int
@konrad1977
konrad1977 / example.swift
Created November 4, 2014 07:49
Example using class method in protocol
protocol FileSaver {
class func savePath() -> String
func saveFile()
var isSaved: Bool { set get }
}
class VideoDocumentStorage : FileSave {
class func savePath() { "Videopath" }
func saveFile() {
@konrad1977
konrad1977 / Singleton.swift
Created November 4, 2014 09:22
Singleton in Swift
class Factory {
}
extension Factory {
class var SharedInstance: Factory {
struct Static {
static let instance: Factory = Factory()
@konrad1977
konrad1977 / TableViewContorllerThatWorks.swift
Created March 19, 2015 10:01
Functional working tableViewController
class TableViewContorllerThatWorks: UITableViewController {
override init(style: UITableViewStyle) {
super.init(style: style)
}
required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
@konrad1977
konrad1977 / gist:b6b8c290888e82473c9c
Last active September 20, 2016 06:51
olika_abstraktions_nivåer
void UpdatePersonWithId(int personId) {
Person personToFind = null;
foreach(person in personList) {
if (person.id == personId) {
personToFind = person;
break;
}
}
SavePerson(personToFind);
}
@konrad1977
konrad1977 / gist:79730ac30643546c39dc
Created June 2, 2015 12:35
SameAbstrationLevel
void UpdatePersonWithId(int personId) {
Person personToFind = FindPersonWithId(personId);
if (personToFind != null)
SavePerson(personToFind);
}
void FindPersonWithId(int personId) {
Person personToFind = null;
foreach(person in personList) {
if (person.id == personId) {