본문 바로가기

전체 글170

Swift Generics - Generics generic 함수나 type을 만들기 위해 함수명이나 타입명 뒤에 ''를 넣고 그 안에 명을 쓰면된다. func repeat(item: T, times: Int) -> [T] { var result = [T]() for i in 0...times { result.append(item) } return result} repeat("knock", 4)-> ["knock", "knock", "knock", "knock", "knock"] classes, enumerations 그리고 structures 뿐만 아니라 함수나 매서드까지 제네릭형식으로 만들 수 있다. // Reimplement the Swift standard library's optional type enum Optional.. 2014. 7. 3.
Swift protocol - protocol 다수위 클래스들이 공통으로 사용할 수 있는 매서드를 묶어 클래스에 적용하는 것을 말한다. protocol을 선언하기 위해서는 키워드 'protocol'을 사용한다. protocol ExampleProtocol { var simpleDescription: String { get } mutating func adjust() } classes, enumerations, stucts는 protocol을 모두 적용할 수 있다. class SimpleClass: ExampleProtocol { var simpleDescription: String = "A very simple class." var anotherProperty: Int = 69105 func adjust() { simpleDesc.. 2014. 7. 3.
Swift struct - struct 구조체를 만들기 위해서는 struct를 사용한다. 구조체는 클래스의 함수나 초기화 등과같은 많은 같은 동작을 제공한다. 구조체와 클래스의 중요한 차이점중에 하나로 구조체는 코드에 값을 전달하고 클래스는 참조를 전달하는 것이다. 예1) struct Card { var rank: Rank var suit: Suit func simpleDescription() -> String { return "The \(rank.simpleDescription()) of \(suit.simpleDescription())" } } let threeOfSpades = Card(rank: .Three, suit: .Spades) let threeOfSpadesDescription = threeOfSpades.si.. 2014. 7. 2.
Hadoop Writable - WritarbleDataInput 과 DataOutput 인터페이스를 기반으로 간단하고 효율적으로 serialization protocol을 구현하는 serializable object이다. 하둡 Map-Reduce Framework 안에서 모든 key나 value Type은 이 인터페이스를 구현한다.일반적인 구현은 readFields를 호출하고 해당 인스턴스를 반환하는 새로운 인스턴스를 생성하는 메소드 static read(DataInput)를 구현한다. public class MyWritable implements Writable { // Some data private int counter; private long timestamp; //out으로 Object의 fields를 Serialize한.. 2014. 7. 2.