2015. 11. 26. 15:26ㆍProgramming/Swift
// playground 에서 아래 소스를 실행해 보자.
1.
//: Playground - noun: a place where people can play
import UIKit
class ExamClass {
deinit {
print("deinit")
}
}
2.
import UIKit
var exam: ExamClass? = ExamClass()
exam = nil
for i in 0...10 {
i * i
}
3.
import UIKit
import XCPlayground
let circleRect = CGRectMake(0,0,300,300)
class CircleView: UIView {
override func drawRect(rect: CGRect) {
let context:CGContextRef = UIGraphicsGetCurrentContext()!
UIColor.whiteColor().setFill()
CGContextFillRect(context, rect)
UIColor.blackColor().setFill()
CGContextFillEllipseInRect(context,circleRect)
}
}
let view = CircleView(frame: circleRect)
XCPShowView("뷰어",view:view)
4.
import UIKit
import XCPlayground
XCPSetExecutionShouldContinueIndefinitely(true)
class Exam: NSObject {
func timerStart() {
NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: "chk", userInfo: nil, repeats:true)
}
var cnt = 0
func chk() {
print("timer check!")
}
}
let exam = Exam()
exam.timerStart()
5.
import UIKit
import XCPlayground
XCPSetExecutionShouldContinueIndefinitely(true)
class Exam: NSObject {
func timerStart() {
NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: "chk", userInfo: nil, repeats:true)
}
var cnt = 0
func chk() {
XCPCaptureValue("count", value:++cnt)
XCPCaptureValue("random", value:arc4random_uniform(100)) //난수 발생
}
}
let exam = Exam()
exam.timerStart()
6.
import UIKit
import XCPlayground
let chk:Int? = 2
let db:[String] = ["","서울","대전","부산"]
if let unrapedChk = chk {
let sido = db[unrapedChk]
print(sido)
} else {
print("Error")
}
7.
class SwiftLab: CustomStringConvertible {
var description: String {
return "안녕하세요"
}
}
let sLab = SwiftLab()
print(sLab)
8.
let apple = 5
assert(apple < 10, "10개미만")
'Programming > Swift' 카테고리의 다른 글
appstore에서 xcode가 다운로드 되지 않을때 (0) | 2016.01.08 |
---|---|
살짝 다른 문법(?) (0) | 2015.12.30 |
시뮬레이션 할 때 키보드가 보이지 않는다? (0) | 2015.11.25 |
libc++abi.dylib terminating with uncaught exception of type nsexception (lldb) (0) | 2015.11.23 |
senchaTouch Download (0) | 2015.10.19 |