2019년 10월 11일 금요일

ViewBinding

layout으로부터 view를 가져오는 가장 원초적인 방법은 findViewById를 사용하는 겁니다.
그런데 이건 워낙에 코드를 장황하게 만들어서 귀찮죠.

그래서 보통 간단하게 사용할 수 있는 Buffer Knife나 Kotlin Android Extensions를 사용합니다.

저도 이전 앱에서는 Buffer Knife를 사용했었고 현재 앱에서는 Kotlin Android Extensions를 사용하고 있습니다.

하지만 구글에서 ViewBinding을 새로 내놨으니 다음에는 ViewBinding을 써야겠네요.

https://proandroiddev.com/hello-viewbinding-goodbye-findviewbyid-edca92b397c

2019년 1월 23일 수요일

Swift By Sundell - Basics

https://www.swiftbysundell.com/basics

- Unit Testing

Xcode에 포함되어 있는 XCTest를 사용한다.

import XCTestCase

class는 XCTestCase를 상혹하고 함수 이름을 test로 시작하게 짓는다.

함수의 내용은 Given - When - Then 의 형태로 구현한다.
"Given these conditions when these actions are performed, then this is the expected outcome"

Given이 중복되는 경우 setUp() 함수를 사용한다.
setUp: 테스트 실행시 항상 먼저 실행되는 함수

- Grand Central Dispatch

GCD: "a different queue of execution"을 통해 asynchronous하게 code가 실행되도록 한다.
DispatchQueue.main
DispatchQueue.global

qos, attributes 등의 속성을 정해줄 수 있다.

- Layout Anchors

Auto layout을 편하게 지정하게 해준다. iOS9에서 새로 소개되었다.

UIView: "a series of anchors"를 포함하고 있다.

anchor를 지정하고 나면 항상 활성화를 해주어야 한다. 다음의 두가지중 한가지 방법을 사용한다.

1. constraint.isActive를 true로 설정
2. NSLayoutConstraint.activate([constraint])

고려해 봐야 할 점 세가지

1. 기본적으로 모든 view는 initial auto resizing mask를 layout constraints로 바꾼다. 이걸 disable하고 싶으면 setTranslatesAutoresizingMaskIntoConstraints를 false로 설정한다.
2. 여러 view로부터의 anchor를 사용하려면 모두가 같은 view hierarchy에 속해 있어야 한다.
3. constraint can be dynamically enabled and disabled. 이러한 경우 constraint를 add/remove 하기 보다는 isActive를 사용하는 것이 낫다.

- Child View Controllers

1. Parent에 add하기

parent.view.addSubView
parent.addChild
child.didMode

2. Parent에서 remove 하기

child.willMode
child.removeFromParent
child.view.removeFromSuperview

=> 항상 3개의 함수를 호출해 주어야 하므로 extension으로 add/remove 함수를 만들어서 사용하면 편할 것이다.

3. UI를 만들 때 Child view controller로 만들면 유용한 점이 있다.

- viewDidLoad나 viewWillAppear 같은 event를 받아서 처리할 수 있다.
- UI와 UI에 관련된 로직을 한군데에 포함함으로서 하나의 단위로 사용될 수 있다.
- View controller는 child로 추가되면 화면 전체를 차지하게 된다. 따라서, 별도로 full screen UI를 위한 layout code를 만들지 않아도 된다.
- 여러곳에서 사용될 수 있게 된다. Navigation Controller에 push 된다던가, child로 embedd 된다던가.

- Codable

Codable은 단순히 Encodable과 Decodable의 type alias이다.

typealias Codable = Decodable & Encodable

예를 들어 struct User가 Codable를 상속받으면 JSONEncode를 사용해서 쉽게 JSON으로 encoding할 수 있다.

struct User: Codable { ... }

let data = try JSONEncoder().encode(user)
let data2 = try JSONDecoder().decode(User.self, from: data)

그런데 json 포맷이 안맞으면 어떻게 해야 할까?
- 변수 이름을 포맷에 맞출까?

json 포맷에 맞는 struct를 만들어 decoding을 한 후 다시 내가 사용하는 struct로 변환한다.

snake case와 camel case가 안맞는 경우 keyDecodingStrategy를 지정해 주면 된다.

decoder.keyDecodingStrategy = .convertToSnakeCase


2018년 6월 10일 일요일

안드로이드 아키텍쳐 패턴을 알아보자

- Clean architecture에 대한 설명

Architecting Android...Reloaded

위 블로그 내용에 대한 Github 소스

https://github.com/android10/Android-CleanArchitecture-Kotlin

- Clean architecture boilerplate using the Model-View-Intent pattern

https://github.com/bufferapp/android-clean-architecture-mvi-boilerplate

- Redux 스타일로 구현하는 방식에 대한 설명. 총 8편의 씨리즈로 되어 있다.

Reactive apps with MVI

- Coordinator Pattern에 대해 알아본다.

In-app navigation with coordinators

위 블로그 내용에 대한 Github 소스

https://github.com/sockeqwe/CoordinatorsAndroid

- 많이 이야기되는 패턴에 대한 장단점 나열

결론으로 Redux 쓰지말고 MVVM 쓰라고 함

MVC/MVP/MVVM/CLEAN/VIPER/REDUX/MVI/PRNSAASPFRUICC

2018년 5월 24일 목요일

오늘의 스터디 - 2018년 2월 23일

Beyond the Basics of Image Optimization

- the old ones
PNG vs JPEG vs GIF

- the new ones
PNG vs JPG vs WebP vs HEIF

mozjpeg

optipng

img-loader for webpack

Blur Up

the contrast swap technique

Never use GIFs

Image processing pipeline: Download -> Decode -> VRAM -> Composite

2018년 5월 7일 월요일

참고하는 Swift 소스

RxSwift

ReSwift

Alamofire

IGListKit
 
GPUImage2

에디터( Editor ) 어떻게 만들지?

Text Editor: Data Structures

아래의 4가지 data type 에 대해 설명한다.

1. Array

Redis로 유명한 Antirez가 재미로 만든 kilo를 기반으로 하여 에디터 만들기를 설명하는 블로그가 있다. 처음 시작으로 좋을 듯.

2. Rope

Rust로 만든 에디터인 xi-editor가 rope로 구현되어 있다.

3. Gap Buffer

Emacs가 Gap Buffer를 사용하여 구현되어 있다고 한다.

4. Piece Table

Atom, Visual Studio Code가 Piece Table로 구현되어 있다고 한다.

2018년 3월 2일 금요일

자바 스터디

String concatenation in Java 9: Untangling invokeDynamic

- 자바와 하스켈에서 Expression problem을 어떻게 해결할 수 있을지 본다.

http://koerbitz.me/posts/Sum-Types-Visitors-and-the-Expression-Problem.html

http://koerbitz.me/posts/Solving-the-Expression-Problem-in-Haskell-and-Java.html

Expression problem: http://www.haruair.com/blog/3338

- C++에서 vtable이 어떻게 구현되는지 간단히 살펴본다.

http://www.michaelburge.us/2017/10/15/haskell-typeclasses-vs-cpp-classes.html

Java language oddities

Arrays are objects

Bytes and shorts are second-class citizens

Private fields and methods are accessible without reflection

Variance in Java and Scala

? extends T : read only인 이유 설명
? super T : write only인 이유 설명
-> 둘 다 실제 타입이 무엇인지 알지 못하기 때문에 발생한다.
-> design note 참조

Generic interfaces 요점

 https://go.dev/blog/generic-interfaces  Generic interface를 정의할 때 최소한의 제약만을 정의하고 실제 구현체들이 자신만의 필요한 제약을 추가할 수 있도록 하는 것이 좋다. pointer receiver를...