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 / 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()
func myFirstFunction() {
let message = "hello world!"
print(message)
}
func getWelcomeMessageToUser(user: String) -> String {
return "Hello " + user
}
var daysInMonth: Int = 30
var currentYear: 2000
let months: 12
enum Sex {
case Male
case Female
case Unknown
}
var index = 0
repeat {
index++
} while index < 100