Skip to content

Instantly share code, notes, and snippets.

@krasi-pl
krasi-pl / RemoteImageSwiftUI.swift
Last active August 10, 2019 18:42
Example of support for remote images for SwiftUI
import SwiftUI
import Combine
import class Kingfisher.KingfisherManager
extension Image {
func remoteImage(from imageURL:URL?) -> some View {
ModifiedContent(content: self, modifier: RemoteImage(loader: ImageLoader(imageURL)))
}
}
//
// FavList.swift
// Tests
//
// Created by blaszm01 on 02/08/2019.
// Copyright © 2019 Mariusz Blaszczyk. All rights reserved.
//
import SwiftUI
import SwiftUI
struct Home: View {
let icons = [
// "moon.stars",
// "moon.stars.fill",
// "star",
// "star.fill",
// "star.lefthalf.fill",
// "star.circle",
#if DEBUG
struct ContentView_Previews : PreviewProvider {
static var previews: some View {
Group {
ForEach(Rating.allCases.identified(by: \.self) ) { rate in
ContentView(rate: rate)
}
}
}
}
struct ContentView : View {
@State var rate:Rating
var body: some View {
HStack {
Spacer()
VStack(alignment: .trailing) {
Text(self.rate.descriptionForRating())
RatePicker(rate: $rate)
}.padding()
}
enum Rating: Int,CaseIterable {
case noRate = 0
case terrible
case bad
case hmmm
case good
case brilliant
func descriptionForRating() -> String {
switch self {
@krasi-pl
krasi-pl / RatePicker.swift
Created July 2, 2019 12:08
Simple 5 Images
struct RatePicker : View {
var body: some View {
HStack {
ForEach((1...5)) { id in
Button(action: {}) {
Image(systemName: "star")
.foregroundColor(.yellow)
.imageScale(.large)
}