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 Button { | |
| func paint() | |
| } | |
| protocol GUIFactory { | |
| func createButton() -> Button | |
| } | |
| class WinButton: Button { | |
| func paint() { |
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 initializePlayerNotification() { | |
| myMusicPlayer!.beginGeneratingPlaybackNotifications() | |
| /* Get notified when the state of the playback changes */ | |
| NSNotificationCenter.defaultCenter().addObserver(self, | |
| selector: "musicPlayerStateChanged:", | |
| name: MPMusicPlayerControllerPlaybackStateDidChangeNotification, | |
| object: nil) | |
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 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") |
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 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 |
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
| 짝수이면 2로 나누고, 홀수이면 3을 곱하고 1을 더하여 최종 값이 1이 될떄까지 몇번이나 도는지 측정 | |
| 두 개의 값을 입력받아 길이가 더 긴 숫자를 출력함. | |
| import Foundation | |
| var a = 3 | |
| var b = 5 | |
| func calcValue(var value: Int) -> Int { | |
| var count = 0 |
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 Foundation | |
| var checkOpenCloseBracket:((String, String) -> Bool)! | |
| checkOpenCloseBracket = { (openBracket, closeBracket) in | |
| var result: Bool | |
| switch (openBracket, closeBracket) { | |
| case _ where openBracket == "{" && closeBracket == "}": | |
| result = true |
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
| 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") | |
| } |
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 | |
| 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 | |
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
| //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]]; |
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
| open -a /Applications/SourceTree.app . |