Skip to content

Instantly share code, notes, and snippets.

View chizcake's full-sized avatar

Henry Yoo chizcake

  • South Korea
  • 07:22 (UTC +09:00)
View GitHub Profile
@chizcake
chizcake / Fixing_Cocoapods_Errors.md
Last active June 13, 2020 07:09
This might help to fix Cocoapods error "Undefined symbols for architecture i386" while building a Xcode project.
@chizcake
chizcake / Publisher+Unwrap.swift
Created March 14, 2020 08:06 — forked from rpassis/Publisher+Unwrap.swift
Combine Recipe - Unwrapping an optional type operator
public protocol OptionalType {
associatedtype Wrapped
var value: Wrapped? { get }
}
extension Optional: OptionalType {
public var value: Wrapped? {
return self
}
}
@chizcake
chizcake / elapsed.swift
Last active June 26, 2018 07:38
Measure elapsed time in Swift
func duration(_ executable: () -> Void) -> TimeInterval {
let startTime = Date()
executable()
return abs(startTime.timeIntervalSinceNow)
}
func measure(_ executable: () -> Void) {
let startTime = Date()
executable()
let endTime = Date()
@chizcake
chizcake / RecordViewController.swift
Created March 24, 2017 08:15
ReplayKit으로 여행 떠나기 - 07. 녹화 화면 다듬기
class RecordViewController: UIViewController {
// MARK: - Properties
...
// 9. 녹화가 시작되면 status bar를 감춥니다.
override var prefersStatusBarHidden: Bool {
return (self.navigationController?.isNavigationBarHidden)!
}
...
@chizcake
chizcake / RecordViewController.swift
Created March 24, 2017 08:06
ReplayKit으로 여행 떠나기 - 06. PreviewViewController 설정
extension RecordViewController: RPPreviewViewControllerDelegate {
func previewControllerDidFinish(_ previewController: RPPreviewViewController) {
// 8. PreviewViewController에서 작업이 끝나면 화면을 MasterViewController로 이동합니다.
previewController.dismiss(animated: true) {
let _ = self.navigationController?.popViewController(animated: true)
}
}
}
@chizcake
chizcake / RecordViewController.swift
Created March 24, 2017 08:03
ReplayKit으로 여행 떠나기 - 05. stopRecording 메소드 구현
func stopRecording() {
let recorder = RPScreenRecorder.shared()
if isRecording {
// 7-1. 사용자가 녹화 중간에 녹음을 종료하는 경우
Log.warning?.message("Stop recording unexpectedly")
recorder.stopRecording(handler: { (previewController, recordingError) in
if let error = recordingError {
Log.error?.message(error.localizedDescription)
} else {
@chizcake
chizcake / RecordViewController.swift
Created March 24, 2017 07:35
ReplayKit으로 여행 떠나기 - 04. startAnimatingMap, stopAnimatingMap 메소드 구현
class RecordViewController: UIViewController {
// MARK: - Properties
var timer = Timer?
var currentLocation: Int = 0
...
func startAnimatingMap() {
if currentLocation == 0 {
showLocationOnMap(index: currentLocation)
currentLocation += 1
@chizcake
chizcake / RecordViewController.swift
Created March 24, 2017 05:34
ReplayKit으로 여행 떠나기 - 03. startRecording 메소드 구현
import ReplayKit
class RecordViewController: UIViewController {
// MARK: - Properties
...
// 0. 현재 녹화 여부를 확인합니다.
var isRecording: Bool = false
...
@chizcake
chizcake / RecordViewController.swift
Created March 24, 2017 04:47
ReplayKit으로 여행 떠나기 - 02. toggle 버튼에 함수 추가하기
@IBAction func barButtonAction(_ sender: UIBarButtonItem) {
if sender.title == "Start Recording" {
...
startRecording()
} else if sender.title == "Stop Recording" {
...
stopRecording()
}
}
@chizcake
chizcake / RecordViewController.swift
Created March 24, 2017 04:45
ReplayKit으로 여행 떠나기 - 01. toggle 버튼 만들기
@IBOutlet weak var barButton: UIBarButtonItem!
@IBAction func barButtonAction(_ sender: UIBarButtonItem) {
if sender.title == "Start Recording" {
Log.info?.message("Start Recording!")
sender.title = "Stop Recording"
} else if sender.title == "Stop Recording" {
Log.info?.message("Stop Recording!")
sender.title = "Start Recording"
}