Skip to content

Instantly share code, notes, and snippets.

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
// 아래 코드는 swift 2.0에서 현재 시간에 하루를 더하는 것을 보여주고 있습니다.
let now = NSDate() // 현재 시간 정보를 넣습니다.
let comp = NSDateComponents() // 하루를 더하기 위해서 NSDateComponents를 하나 만듭니다.
comp.setValue(1, forKey: "day") // 위에서 만든 곳에 1일을 넣습니다. forKey를 바꾸면 다른 것도 넣을 수 있습니다.
let myCal = NSCalendar.init(calendarIdentifier: NSCalendarIdentifierGregorian) // 하루를 더해서 넣을 NSCalendar를 하나 만듭니다.
let tomorrow = myCal!.dateByAddingComponents(comp, toDate: now, options: NSCalendarOptions(rawValue: 0)) // 위에서 만든 현재 시간인 now에 myCal을 이용하여 하루를 더해서 tomorrow에 넣습니다.
let string = "나는 전설이다."
print(string.characters.count)
let newString = "I Am Legend."
print(newString.characters.count)
@dialektike
dialektike / NSDataString.swift
Created October 12, 2015 09:35
from String to NSData, from NSData to String
var swift_string = "lorem ipsum dolor sit amet"
// from String to NSData
let data = swift_string.dataUsingEncoding(NSUTF8StringEncoding)
print(data)
// from NSData to String
var out: String = String(data:data!, encoding:NSUTF8StringEncoding)!
print(out) // print "lorem ipsum dolor sit amet"
// from string to int in swift
let intString: String = "256"
let stringInt: Int? = Int(intString)