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
| extension FileManager { | |
| func documentDirectory() -> URL { | |
| return FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0] | |
| } | |
| class func libraryDirectory() -> URL { | |
| return try! FileManager.default.url(for: .libraryDirectory, in: .userDomainMask, appropriateFor: nil, create: false) | |
| } | |
| } |
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
| // MARK: - Body | |
| var body: some View { | |
| Text("Tap here to check") | |
| .onTapGesture { | |
| let str = "Test Message" | |
| let url = self.getDocumentsDirectory().appendingPathComponent("message.txt") | |
| do { | |
| try str.write(to: url, atomically: true, encoding: .utf8) | |
| let input = try String(contentsOf: url) |
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
| func getDocumentsDirectory() -> URL { | |
| let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask) | |
| return paths[0] | |
| } //: get Documents directory func |
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 users = [ | |
| User(firstName: "Arnold", lastName: "Igh"), | |
| User(firstName: "Ryan", lastName: "Fgc"), | |
| User(firstName: "None", lastName: "Abc") | |
| ].sorted() // after operator overloaded, we can use .sorted() | |
| // MARK: - Body | |
| var body: some View { | |
| List(users) { user in |
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
| struct User: Identifiable, Comparable { | |
| static func < (lhs: User, rhs: User) -> Bool { | |
| lhs.lastName < rhs.lastName | |
| } | |
| let id = UUID() | |
| let firstName: String | |
| let lastName: String | |
| } |
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
| // | |
| // ImageSaver.swift | |
| // Instafilter | |
| // | |
| // Created by Ryan J. W. Kim on 2021/10/29. | |
| // | |
| import UIKit | |
| class ImageSaver: NSObject { |
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
| // change it | |
| @State var currentFilter: CIFilter = CIFilter.sepiaTone() | |
| // change applyProcessing and add setFilter func | |
| func applyProcessing() { | |
| // adapting to each filter params to safely workaround with input param | |
| let inputKeys = currentFilter.inputKeys | |
| if inputKeys.contains(kCIInputIntensityKey) { currentFilter.setValue(filterIntensity, forKey: kCIInputIntensityKey) } | |
| if inputKeys.contains(kCIInputRadiusKey) { currentFilter.setValue(filterIntensity * 200, forKey: kCIInputRadiusKey) } |
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
| struct MultipleActionSheet: View { | |
| // MARK: - Properties | |
| // alert for alert , actionSheet for actionSheet. They are similar in many functions | |
| @State private var showingActionSheet = false | |
| @State private var backgroundColor = Color.white | |
| // MARK: - Body | |
| var body: some View { | |
| Text("Touch here to change color") | |
| .frame(width: 300, height: 300) |
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
| struct SwiftUIView: View { | |
| var body: some View { | |
| AsyncImage(url: URL(string: "https://stackoverflow.design/assets/img/logos/so/logo-stackoverflow.png")) { image in | |
| image.resizable() | |
| .scaledToFit() | |
| } placeholder: { | |
| ProgressView() | |
| } | |
| .frame(width: 200, height: 200) | |
| } |
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 CoreImage | |
| import CoreImage.CIFilterBuiltins | |
| import SwiftUI | |
| struct ContentView: View { | |
| // MARK: - Properties | |
| @State private var image: Image? | |
| @State private var filterIntensity = 0.5 | |
| @State private var showingImagePicker = false |