swift5

How to capture high resolution image from UIView

二次信任 提交于 2021-02-18 18:49:32
问题 I hope you all are safe. I know this question asked several times but not getting a perfect answer. I just wanted to capture an image from UIView with high resolution the main this is that image should not be a blur. I have tried this code extension UIView { func asImage() -> UIImage { let renderer = UIGraphicsImageRenderer(size: self.bounds.size) let capturedImage = renderer.image { (ctx) in self.drawHierarchy(in: self.bounds, afterScreenUpdates: true) } return capturedImage } } Right now

How to capture high resolution image from UIView

£可爱£侵袭症+ 提交于 2021-02-18 18:48:57
问题 I hope you all are safe. I know this question asked several times but not getting a perfect answer. I just wanted to capture an image from UIView with high resolution the main this is that image should not be a blur. I have tried this code extension UIView { func asImage() -> UIImage { let renderer = UIGraphicsImageRenderer(size: self.bounds.size) let capturedImage = renderer.image { (ctx) in self.drawHierarchy(in: self.bounds, afterScreenUpdates: true) } return capturedImage } } Right now

SwiftUI - is it possible to get didSet to fire when changing a @Published struct?

人走茶凉 提交于 2021-02-18 11:23:05
问题 I have just updated to XCode 11.4 and some of my code has stopped working. I have some @Published struct variables in an ObservableObject . Previously, when I updated properties on the struct, the didSet method would fire on the published property, but that's not the case anymore. Is it possible that this behaviour has changed by design in the latest update to Swift? Here's a trivial example: import SwiftUI struct PaddingRect { var left: CGFloat = 20 var right: CGFloat = 20 } final class

Decodable for JSON with two structs under the same tag

假如想象 提交于 2021-02-17 05:26:05
问题 I have this json: { "stuff": [ { "type":"car", "object":{ "a":66, "b":66, "c":66 }}, { "type":"house", "object":{ "d":66, "e":66, "f":66 }}, { "type":"car", "object":{ "a":66, "b":66, "c":66 }} ]} As you can see for " car " and " house " there are different "object" structs, but both under the tag "object". It would be ideal if one ended up with something like struct StuffItem: Decodable { let type: TheType let car: Car let house: House } Is there some Codable, swifty, way to handle this? 回答1

Collection View layout bug when selectItem (Swift 5)

杀马特。学长 韩版系。学妹 提交于 2021-02-17 01:52:51
问题 After selecting cell from viewDidLoad Layout is change Before select cell After select cell let indexPath = IndexPath(row: SelectedFolderIndex, section: 0) collectionView.selectItem(at: indexPath, animated: false, scrollPosition: .centeredVertically) Layout func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { return CGSize(width: collectionView.frame.width/2.2, height: 55) } ViewDidLoad let

How can I decode a dictionary from a JSON when I don't know the keys of the dictionary? [duplicate]

久未见 提交于 2021-02-13 17:35:41
问题 This question already has answers here : How to parse one block of JSON data instead of the entire JSON sequence (2 answers) Want to view json metadata (1 answer) Closed 1 year ago . I try to decode a JSON of this structure: https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=MSFT&interval=5min&apikey=demo The "Time Series (5min)" Object is a dictionary of Objects, but I don't know how to decode this JSON using the Codable Protocol when the keys of the dictionary are

Json data not showing on tableView swift 5

这一生的挚爱 提交于 2021-02-11 17:01:25
问题 I fetched the data and it is showing when printing but when i try to display it on tableview.Nothing is coming Am i placing tableview.reloadData in wrong place ? override func viewDidLoad() { super.viewDidLoad() fetchData() tableView.reloadData() } func fetchData() { if let url = URL(string: urlConstant) { let session = URLSession(configuration: .default) let task = session.dataTask(with: url) { (data, res, err) in if err == nil { let decoder = JSONDecoder() if let safeData = data { do{ let

SwiftUI: Stepper Binding is not working in the subview

故事扮演 提交于 2021-02-11 15:12:35
问题 I have a stepper control in the main list view as well as in the detail view. the code is exactly the same. However the stepper in main view is working perfectly, but the subview is stopping after 1 increment (as it looks like the upper bound is set.) The funny thing is it was working some time ago, after improvements, i am not able to trace what exactly changed it s behaviour. Here is the code. struct QuestionCardTest: View { @Binding var question : SurveyQuestion var body: some View {

SwiftUI: Stepper Binding is not working in the subview

可紊 提交于 2021-02-11 15:08:33
问题 I have a stepper control in the main list view as well as in the detail view. the code is exactly the same. However the stepper in main view is working perfectly, but the subview is stopping after 1 increment (as it looks like the upper bound is set.) The funny thing is it was working some time ago, after improvements, i am not able to trace what exactly changed it s behaviour. Here is the code. struct QuestionCardTest: View { @Binding var question : SurveyQuestion var body: some View {

Cannot store custom class in UserDefaults - Attempt to insert non-property list

↘锁芯ラ 提交于 2021-02-11 13:04:17
问题 I'm trying to store a custom class in UserDefaults , however I'm getting the "Attempt to insert non-property list" error as soon as the app starts. I have successfully stored arrays of custom classes, so I followed the same principle, but something is wrong. This is my class: import Foundation public class PlanRouteFilters: NSObject, NSCoding, Codable { var favoriteLines: Bool var routeType: Int var bus: Bool var train: Bool var subway: Bool var electric: Bool var sharedCar: Bool var bike: