Skip to content

Instantly share code, notes, and snippets.

@torpedo87
torpedo87 / fetching.md
Created March 27, 2019 07:32
fetching from core data

fetching 기술

NSFetchRequest

  • A description of search criteria used to retrieve data from a persistent store.
  • 같은 request를 여러번 호출해야 할 경우에는 xcdatamodeld 파일에서 request를 생성해서 사용할 수 있다. 단 이렇게 하면 정렬 순서를 설정할 수 없는 단점이 있다
  • resultType : The result type of the fetch request.

NSFetchRequestResultType

@torpedo87
torpedo87 / coreDataStack.md
Last active March 30, 2019 05:54
core data stack

core data stack

  • context(managed object) <—> coordinator(persistent store) <—-> SQLite
  • The managed object context keeps track of its managed objects and all the changes you make to them
  • NSPersistentContainer : A container that encapsulates the Core Data stack in your application. 스택 세팅을 위한 helper class

Xcode 도움없이 core data 세팅하기

NSManagedObjectModel

  • A programmatic representation of the .xcdatamodeld file describing your objects.
  • database schema 역할
@torpedo87
torpedo87 / modeling.md
Created March 25, 2019 06:09
core data 모델링

attribute 데이터 타입

  • 이미지 같은 경우는 Binary data 타입으로 설정 가능. 이 때 allows extenrnal storage 등의 옵션 설정을 통해 메모리 이슈를 완화할 수 있다
  • String, Interger, Double, Boolean, Date, Binary data 등의 타입을 저장 가능
  • Transformable 타입 : custom 타입을 저장하고 싶을 때에는 먼저NSCoding 프로토콜을 준수하도록 만든 후에 Transformable 타입으로 설정해도 된다
  • NSCoding : A protocol that enables an object to be encoded and decoded for archiving and distribution.

entity 를 NSManagedObject 상속하는 클래스로 변환하기

  • entity를 좀 더 용이하게 다루기 위해서 하는 작업이다
@torpedo87
torpedo87 / saveFetch.md
Created March 24, 2019 08:35
save and fetch

core data

  • Manage object graphs and object lifecycle, including persistence.
  • By default, Core Data uses a SQLite database as the persistent store
  • import 해야 사용가능

NSPersistentContainer

  • A container that encapsulates the Core Data stack in your application.
  • app delegate 에서 접근 가능
@torpedo87
torpedo87 / storyboard.md
Created January 25, 2019 10:46
storyboard

storyboard

  • static tableview 는 datasource 코드없이 테이블 구성 가능
  • Static table views are only valid when embedded in UITableViewController instances

dock

  • 해당 scene 의 top level object 를 나타낸다
  • view controller
  • first responder
  • exit : segue를 인자로 갖는 모든 액션메소드에 접근할 수 있다. 따라서 현재 컨트롤러에서 해당 segue 를 통해 다른 컨트롤러로 탈출
@torpedo87
torpedo87 / workflow.md
Created January 23, 2019 04:08
work flow

app dev

design

develop

Continuous Integration

  • Xcode 에서 source control 메뉴에서 create repository 해서 로컬에 버전저장하기
  • remote 를 Github 계정과 연결하기
  • manage scheme -> shared 체크되어 있어야 한다
@torpedo87
torpedo87 / customReactiveExt.md
Created January 22, 2019 06:55
custom Reactive extension

custom reactive extension

extension Reactive where Base: URLSession {
  
  //response
  func response(request: URLRequest) -> Observable<(HTTPURLResponse, Data)> {
    
    return Observable.create({ observer in
      
      let task = self.base.dataTask(with: request, completionHandler: { (data, response, error) in
@torpedo87
torpedo87 / retest.md
Last active January 22, 2019 06:56
RxTest

RxTest

  • 에러가 맞는지 확인하는 경우의 테스트는 에러가 일치하는지를 테스트하지 말고 do, try, catch 를 사용한다
func testError() {
  var erroredCorrectly = false
  let observable = URLSession.shared.rx.json(request: self.errorRequest)
  do {
    let _ = try observable.toBlocking().first()
    assertionFailure()
  } catch (RxURLSessionError.unknown) {
@torpedo87
torpedo87 / scheduler.md
Created January 21, 2019 11:16
scheduler

scheduler

  • 프로세스가 발생하는 컨텍스트(쓰레드, 디스패치큐 등)
  • cold observable은 구독을 해야 이벤트를 방출하는 시퀀스로서 구독하기 전에는 아무것도 생성하지 않으므로 컨텍스트가 설정되어 있지 않은 상태로서 subscribeOn 이 유효
  • hot observable은 구독 전에도 이미 이벤트를 방출하고 있는 시퀀스로서 이미 컨텍스트가 있으며 RxSwift가 이를 통제할 수 없으므로 subscribeOn 이 소용없음

subscribeOn

  • Wraps the source sequence in order to run its subscription and unsubscription logic on the specified scheduler.
  • 구독 이전 연산자들의 클로저가 실행되는 장소를 지정
  • 원래는 자동으로 현재 스레드에서 시퀀스가 이벤트를 방출, 가공하나 이 연산자를 통해 바꿀 수 있다
@torpedo87
torpedo87 / errorHandling.md
Created January 21, 2019 06:51
error handling

error handling

  • 에러발생시 시퀀스가 종료하지 않도록 처리해야한다

throw

  • When you want to error out inside a flatMap operator, you should use throw as in regular Swift code

catch