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 SwiftUI | |
import Introspect | |
struct ContentView : View { | |
@State var text = "" | |
var body: some View { | |
VStack { | |
TextField("Enter some text", text: $text) |
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 SwiftUI | |
import AVKit | |
import CoreImage | |
import CoreImage.CIFilterBuiltins | |
struct ContentView: View { | |
@State private var currentFilter = 0 | |
var filters : [CIFilter?] = [nil, CIFilter.sepiaTone(), CIFilter.pixellate(), CIFilter.comicEffect()] |
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
struct Anything<Wrapper : UIView>: UIViewRepresentable { | |
typealias Updater = (Wrapper, Context) -> Void | |
var makeView: () -> Wrapper | |
var update: (Wrapper, Context) -> Void | |
init(_ makeView: @escaping @autoclosure () -> Wrapper, | |
updater update: @escaping (Wrapper) -> Void) { | |
self.makeView = makeView | |
self.update = { view, _ in update(view) } |
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
struct SwitchLayouts : View{ | |
@State private var switchStack: Bool = false | |
var body: some View{ | |
let layout = switchStack ? AnyLayout(HStack()) : AnyLayout(VStack()) | |
VStack{ | |
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
Grid { | |
GridRow { | |
Color.red | |
.gridCellColumns(2) | |
Grid{ | |
GridRow{ | |
Color.orange | |
} | |
GridRow{ |
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
ZStack{ | |
Circle().fill(.red.gradient.shadow(.drop(color: .black, radius: 10)).shadow(.inner(radius: 10))) | |
.frame(width: 150, height: 150) | |
Image(systemName: "swift") | |
.resizable() | |
.aspectRatio(contentMode: .fit) | |
.frame(width: 75, height: 75) | |
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 resizedImage(for size: CGSize) -> UIImage? { | |
let image = self.cgImage | |
let context = CGContext(data: nil, | |
width: Int(size.width), | |
height: Int(size.height), | |
bitsPerComponent: image!.bitsPerComponent, | |
bytesPerRow: Int(size.width), | |
space: image?.colorSpace ?? CGColorSpace(name: CGColorSpace.sRGB)!, | |
bitmapInfo: image!.bitmapInfo.rawValue) | |
context?.interpolationQuality = .high |
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 UIImage { | |
class func imageFromColor(color: UIColor, size: CGSize=CGSize(width: 1, height: 1), scale: CGFloat) -> UIImage? { | |
UIGraphicsBeginImageContextWithOptions(size, false, scale) | |
color.setFill() | |
UIRectFill(CGRect(origin: CGPoint.zero, size: size)) | |
let image = UIGraphicsGetImageFromCurrentImageContext() | |
UIGraphicsEndImageContext() | |
return image | |
} |
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
let modelConfig = MLModelConfiguration() | |
modelConfig.computeUnits = .cpuAndGPU | |
let updateTask = try MLUpdateTask(forModelAt: modelURL, trainingData: batchProvider(), configuration: modelConfig, | |
progressHandlers: MLUpdateProgressHandlers(forEvents: [.trainingBegin,.epochEnd], | |
progressHandler: { (contextProgress) in | |
print(contextProgress.event) | |
}) { (finalContext) in | |
if finalContext.task.error?.localizedDescription == nil |
NewerOlder