This file contains 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
func blurFaces(in image: UIImage) -> UIImage? { | |
guard let ciImage = CIImage(image: image)? | |
.oriented(.init(image.imageOrientation)) else { | |
return nil | |
} | |
// this image will use as the "mask map" | |
var maskCanvasImage = CIImage.empty() | |
.cropped(to: ciImage.extent) |
This file contains 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
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) { | |
picker.dismiss(animated: true) | |
guard let image = info[.originalImage] as? UIImage else { | |
return | |
} | |
imageView.image = image | |
// layout logic, fit image view size to image ratio... | |
... |
This file contains 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
extension CGImagePropertyOrientation { | |
init(_ uiOrientation: UIImage.Orientation) { | |
switch uiOrientation { | |
case .up: self = .up | |
case .upMirrored: self = .upMirrored | |
case .down: self = .down | |
case .downMirrored: self = .downMirrored | |
case .left: self = .left | |
case .leftMirrored: self = .leftMirrored | |
case .right: self = .right |
This file contains 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
func getFaceRects(in image: UIImage, normalizedTo rect: CGRect) -> [CGRect] { | |
guard var ciImage = CIImage(image: image) else { | |
print("Couldn't create CIImage.") | |
return [] | |
} | |
// correct the orientation becuase `CIImage.init` can lose it | |
ciImage = ciImage.oriented(.init(image.imageOrientation)) | |
let scaleFactorX = rect.width / ciImage.extent.width |
This file contains 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 | |
class ImageProcessingService { | |
private let ciContext = CIContext() | |
private lazy var ciDetector = CIDetector(ofType: CIDetectorTypeFace, context: ciContext)! | |
} |
This file contains 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 Combine | |
class LibraryViewController: UIViewController { | |
@IBOutlet weak var collectionView: UICollectionView! | |
private var tokens = [AnyCancellable]() | |
// We're making the viewModel property lazy so it can access `self` during initialization. | |
private lazy var viewModel = LibraryViewModel(collectionView: collectionView) |
This file contains 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
class LibraryViewModel: CollectionViewModel<NoteCell> { | |
init(collectionView: UICollectionView) { | |
super.init(collectionView: collectionView, cellReuseIdentifier: "NoteCell") | |
} | |
} | |
// MARK: - UICollectionViewDelegate Implementation | |
extension LibraryViewModel: UICollectionViewDelegate { | |
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { |
This file contains 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 update() { | |
var snapshot = NSDiffableDataSourceSnapshot<Section, Item>() | |
snapshot.appendSections([.main]) | |
snapshot.appendItems(items.value) | |
dataSource?.apply(snapshot) | |
} | |
public func add(_ items: [Item]) { | |
items.forEach { | |
self.items.value.append($0) |
This file contains 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
// MARK: - Setup Logic | |
extension CollectionViewModel { | |
private func cellProvider(_ collectionView: UICollectionView, indexPath: IndexPath, item: Item) -> UICollectionViewCell? { | |
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellIdentifier, for: indexPath) as! CellType | |
cell.provide(item) | |
return cell | |
} | |
public func makeDataSource() -> DataSource { |
This file contains 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
enum Section { | |
case main | |
} |
NewerOlder