This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private func addItem2() async throws { | |
// CheckedContinuation<Void, Error>)と型書かないといけないんだなあこれが | |
try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<Void, Error>) in | |
writeContext.perform { | |
let newItem = Item(context: writeContext) | |
newItem.timestamp = Date() | |
do { | |
try writeContext.save() | |
continuation.resume() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import _Concurrency | |
/* | |
DAOでアクター使って行きたいとき(モチベーション的には非同期処理であることを矯正したい場合)、 | |
設計としては | |
actor型をDAOの型とするパターンと、globalActorをDAOで利用する場合の2パターンある。 | |
SampleAがactorを使うパターンで、SampleBがglobalActorを使うパターン。 | |
*/ | |
enum SampleA { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let largeArray = ... | |
... | |
let (array1, array2) = { array -> ([Object], [Object]) | |
var array1: [Object] = [] | |
var array2: [Object] = [] | |
array.forEach { | |
if $0.type == .nanika { | |
array1.append($0) | |
} else { | |
array2.append($0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Combine | |
struct ReducerContainer { | |
let reducer: () -> (AnyPublisher<Int, Never>) | |
init(reducer: @escaping () -> (AnyPublisher<Int, Never>)) { | |
self.reducer = reducer | |
} | |
static func combine(_ reducers: [ReducerContainer]) -> ReducerContainer { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct ContentView: View { | |
var body: some View { | |
ZStack(alignment: .top) { | |
MapView() | |
SlideOverCard { | |
VStack { | |
Text("Half Modal") | |
.font(.headline) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import RxSwift | |
import Foundation | |
let queue = DispatchQueue.global(qos: .background) | |
// 念の為に書くと、ここはメインスレッドで呼び出している | |
let stream = Observable.just(1) | |
.flatMap { value -> Observable<Int> in | |
print("flatMap: isMain \(Thread.isMainThread)") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
XCRUN = /usr/bin/env xcrun --sdk macosx | |
SWIFT_FORMAT_PATHS = <フォーマットしたいパス> | |
format: | |
$(XCRUN) swift run -c release \ | |
swift-format --mode format --recursive --in-place $(SWIFT_FORMAT_PATHS) | |
format-skip-build : | |
$(XCRUN) swift run -c release --skip-build \ | |
swift-format --mode format --recursive --in-place $(SWIFT_FORMAT_PATHS) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import MobileCoreServices | |
import CoreImage | |
public struct JPEGConverter { | |
let data: Data | |
let dataUTI: String | |
public init(data: Data, with dataUTI: String) { | |
self.data = data |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import PhotosUI | |
class ViewController: UIViewController { | |
@IBAction func presentPickerForImagesIncludingLivePhotos(_ sender: Any) { | |
presentPicker(filter: PHPickerFilter.images) | |
} | |
private func presentPicker(filter: PHPickerFilter) { |