Skip to content

Instantly share code, notes, and snippets.

View trilliwon's full-sized avatar
🎯
Focusing

WonJo trilliwon

🎯
Focusing
View GitHub Profile
@trilliwon
trilliwon / uiimage-data.swift
Last active January 12, 2024 14:45
Swift UIImage to Data, Data to UIImage
// Swift4
let image = UIImage(named: "sample")
let data = image?.pngData()
let data = image?.jpegData(compressionQuality: 0.9)
let uiImage: UIImage = UIImage(data: imageData)
// deprecated
// var imageData: Data = UIImagePNGRepresentation(image)
@dynamicMemberLookup
public struct Builder<Base> {
public var build: () -> Base
public init(_ build: @escaping () -> Base) {
self.build = build
}
public init(_ base: Base) {
@trilliwon
trilliwon / Reencoder.swift
Last active July 9, 2023 08:00
Reencoder ios swift
import AVFoundation
import os.log
/// https://developer.apple.com/library/archive/documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/05_Export.html
/**
Steps
- Use serialization queues to handle the asynchronous nature of reading and writing audiovisual data
- Initialize an asset reader and configure two asset reader outputs, one for audio and one for video
- Initialize an asset writer and configure two asset writer inputs, one for audio and one for video
//: [Table of Contents](Table%20of%20Contents) | [Next](@next)
import Foundation
/*:
## Number Formatter
Provides localized representations of units and measurements.
*/
let numberFormatter = NumberFormatter()
@trilliwon
trilliwon / How to turn off the shutter sound when capture? AVFoundation.swift
Created December 21, 2019 05:08
How to turn off the shutter sound when capture? AVFoundation
class PhotoCapture {
// here some stuff for capture image, such as capture session, configurations, photo output
// More detail : https://github.com/trilliwon/ArtCamera/blob/master/Camera/Controllers/PhotoCapture.swift
}
// MARK: - AVCapturePhotoCaptureDelegate
extension PhotoCapture: AVCapturePhotoCaptureDelegate {
func photoOutput(_ output: AVCapturePhotoOutput, willCapturePhotoFor resolvedSettings: AVCaptureResolvedPhotoSettings) {
AudioServicesDisposeSystemSoundID(1108)
}
$ git branch | fzf
$ git switch $(git branch | fzf)
$ git checkout $(git for-each-ref refs/heads/ --format='%(refname:short)' | fzf)

Or add below script to .zshrc

@trilliwon
trilliwon / CIFilter+Extension.swift
Created February 15, 2019 09:41 — forked from ha1f/CIFilter+Extension.swift
CIFilter+Extension.swift
//
// Created by はるふ on 2017/12/11.
// Copyright © 2017年 ha1f. All rights reserved.
//
import Foundation
import CoreImage
import AVFoundation
extension CIFilter {
import Foundation
@dynamicMemberLookup
public struct Builder<Base: AnyObject> {
let _build: () -> Base
public init(_ build: @escaping () -> Base) {
self._build = build
@trilliwon
trilliwon / makeI18N.sh
Last active January 11, 2022 08:03
makeI18N
#!/bin/sh
echo "generating I18N.swift"
touch tempI18N.swift
echo "struct I18N {" >> tempI18N.swift
inputfile=${SRCROOT}/Pomodoro/Resources/en.lproj/Localizable.strings
while IFS= read -r line
@trilliwon
trilliwon / StrToString.swift
Last active January 10, 2022 05:59
String to Data, Data to String
// String to Data utf8
let strData: Data = Data("String".utf8)
// Data to String
let str = String(data: strData, encoding: .utf8)