Skip to content

Instantly share code, notes, and snippets.

@minsOne
minsOne / Abstract_Factory_Pattern.swift
Created September 23, 2014 13:14
Abstract_Factory_Pattern
protocol Button {
func paint()
}
protocol GUIFactory {
func createButton() -> Button
}
class WinButton: Button {
func paint() {
@minsOne
minsOne / gist:dd0bcf00721046c26782
Created March 7, 2015 19:05
MPMusicPlayerControllerNotification
func initializePlayerNotification() {
myMusicPlayer!.beginGeneratingPlaybackNotifications()
/* Get notified when the state of the playback changes */
NSNotificationCenter.defaultCenter().addObserver(self,
selector: "musicPlayerStateChanged:",
name: MPMusicPlayerControllerPlaybackStateDidChangeNotification,
object: nil)
func readFile(fileName: String, fileType: String) -> String{
var fileRoot = NSBundle.mainBundle().pathForResource(fileName, ofType: fileType)
var contents = NSString.stringWithContentsOfFile(fileRoot!, encoding: NSUTF8StringEncoding, error: nil)
return contents
}
// example: read file.txt
var contents = readFile("file", fileType: "txt")
@minsOne
minsOne / BattleShip.swift
Created April 12, 2015 07:45
Functional Programming Example in Swift
import Foundation
import UIKit
typealias Position = CGPoint
typealias Distance = CGFloat
typealias Region = Position -> Bool
func inRange1(target: Position, range: Distance) -> Bool {
return sqrt(target.x * target.x + target.y * target.y) <= range
짝수이면 2로 나누고, 홀수이면 3을 곱하고 1을 더하여 최종 값이 1이 될떄까지 몇번이나 도는지 측정
두 개의 값을 입력받아 길이가 더 긴 숫자를 출력함.
import Foundation
var a = 3
var b = 5
func calcValue(var value: Int) -> Int {
var count = 0
import Foundation
var checkOpenCloseBracket:((String, String) -> Bool)!
checkOpenCloseBracket = { (openBracket, closeBracket) in
var result: Bool
switch (openBracket, closeBracket) {
case _ where openBracket == "{" && closeBracket == "}":
result = true
override func shouldAutorotate() -> Bool {
return isRotate
}
override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
if UIDevice.currentDevice().orientation.isLandscape.boolValue {
println("Now Device Orientation is Landscape")
} else {
println("Now Device Orientation is Portrait")
}
import UIKit
import XCPlayground
let containerView = UIView(frame: CGRect(x: 0.0, y: 0.0, width: 375.0, height: 667.0))
XCPShowView("Container View", containerView)
let circle = UIView(frame: CGRect(x: 0.0, y: 0.0, width: 50.0, height: 50.0))
circle.center = containerView.center
circle.layer.cornerRadius = 25.0
//The setup code (in viewDidLoad in your view controller)
UITapGestureRecognizer *singleFingerTap =
[[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(handleSingleTap:)];
[self.view addGestureRecognizer:singleFingerTap];
[singleFingerTap release];
//The event handling method
- (void)handleSingleTap:(UITapGestureRecognizer *)recognizer {
CGPoint location = [recognizer locationInView:[recognizer.view superview]];
open -a /Applications/SourceTree.app .