Post

Replies

Boosts

Views

Activity

Reply to Refreshing Widget from Notification Extension
Similar issue. Not on notification but I would need to reload the timeline (in order to change some content passed by the app itself). reload doesn't reload with new data. In the code, Util is to have a singleton to share data with the App. struct LoadStatusProvider: TimelineProvider { &#9;&#9; &#9;&#9;func placeholder(in context: Context) -> SimpleEntry { &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;SimpleEntry(date: Date(), loadEntry: 0, message: Util.shared.globalToPass) &#9;&#9;} &#9;&#9;func getSnapshot(in context: Context, completion: @escaping (SimpleEntry) -> ()) { &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;let entry = SimpleEntry(date: Date(), loadEntry: 0, message: Util.shared.globalToPass) &#9;&#9;&#9;&#9;completion(entry) &#9;&#9;} &#9;&#9;func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> ()) { &#9;&#9;&#9;&#9;var entries: [SimpleEntry] = [] &#9;&#9;&#9;&#9;// Generate a timeline consisting of five entries an hour apart, starting from the current date. &#9;&#9;&#9;&#9;let currentDate = Date() &#9;&#9;&#9;&#9;for minuteOffset in 0 ..< 2 { &#9;&#9;&#9;&#9;&#9;&#9;let entryDate = Calendar.current.date(byAdding: .minute, value: 5*minuteOffset, to: currentDate)! &#9;&#9;&#9;&#9;&#9;&#9;let entry = SimpleEntry(date: entryDate, loadEntry: minuteOffset, message: Util.shared.globalToPass) &#9;&#9;&#9;&#9;&#9;&#9;print(Util.shared.globalToPass) &#9;&#9;&#9;&#9;&#9;&#9;entries.append(entry) &#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;let timeline = Timeline(entries: entries, policy: .atEnd)&#9; // .after(currentDate.addingTimeInterval(300.0))) //&#9;.atEnd) &#9;&#9;&#9;&#9;completion(timeline) &#9;&#9;} } struct SimpleEntry: TimelineEntry { &#9;&#9;let date: Date &#9;&#9;let loadEntry: Int &#9;&#9;let message: String }
Topic: App & System Services SubTopic: General Tags:
Dec ’20
Reply to Calling Barcodescanner from another class, cant retrieve the data?
&#9;&#9;&#9;&#9;Partynallen().readerVC.delegate = Partynallen().self // DONT KNOW IF THIS IS CORRECT? No, it is not. And &#9;&#9;&#9;&#9;&#9;&#9;Partynallen().readerVC.modalPresentationStyle = .formSheet &#9;&#9;&#9;&#9;&#9;&#9;present(Partynallen().readerVC, animated: true) isn't either. Each time you call Partynallen(), you create a new instance which disappears when you end the func. Is Partynallen associated to a VC in IB ? To keep an instance, you have to create it: class NewViewController: UIViewController { &#9;&#9; &#9;&#9;var partynallen: Partynallen? &#9;&#9; &#9;&#9;override func viewDidLoad() { &#9;&#9;&#9;&#9;super.viewDidLoad() &#9;&#9;&#9;&#9;// Do any additional setup after loading the view. &#9;&#9;&#9;&#9;partynallen = Partynallen() &#9; // readerVC.delegate is already initiated in Partynallen ; what do you want to do here ? &#9;&#9;&#9; // Partynallen().readerVC.delegate = Partynallen().self // DONT KNOW IF THIS IS CORRECT? &#9;&#9;} &#9;&#9;&#9;&#9;@IBAction func scan(_ sender: UIButton) { &#9;&#9;&#9;&#9;&#9;&#9;// Partynallen().readerVC.modalPresentationStyle = .formSheet &#9;&#9;&#9;&#9;&#9;&#9;// present(Partynallen().readerVC, animated: true) &#9;&#9;&#9;&#9;&#9;&#9;partynallen.readerVC.modalPresentationStyle = .formSheet &#9;&#9;&#9;&#9;&#9;&#9;present(partynallen.readerVC, animated: true) &#9;&#9;} &#9;&#9; }
Topic: Programming Languages SubTopic: Swift Tags:
Dec ’20
Reply to Calling Barcodescanner from another class, cant retrieve the data?
In addition to the code, could you tell: do you ask for authorisation to use the camera ? did you set the info.plist entry to ask for permission ? Before i applied your code, the barcode had a cancel button which didnt respond when pushing, after applying your code i can push it but the image freezes when i do, same thing happens when i scan a barcode. - where does it freeze exactly ? Do you see the camera image ?
Topic: Programming Languages SubTopic: Swift Tags:
Dec ’20
Reply to How to save UIImage array and then use it?
And… where is the problem ? As long as the app is active, imgArr must do the job. So, what's the problem ? getting the images from saved files ? for saving, you had another post. Does it work ? Please: explain exactly the problem does it crash ? if yes, show the crash log doesn't it do what you expect ? if yes, Explain. in any cases, show your code for saving and reading images
Topic: Programming Languages SubTopic: Swift Tags:
Dec ’20
Reply to Decoding JSON SwifUI
I'm trying to decode a JSON File but it's not working and I can't understand why It is not working is not an information. what do you get ? Is it a wrong result (which) or no result at all ? (what do you get in loaded ? Does it crash ? If so, what is the crash log I looked at the code: Isn't there a comma missing at the end of line 5 in JSON file ? Note: when you paste code, use Paste and Match Style, to avoid the extra blank lines that make code quasi impossible to analyse. import SwiftUI struct Search: View { &#9;&#9; &#9;&#9;let sf: [SF] = Bundle.main.decode("sf.json") &#9;&#9;@State private var searchText: String = "" &#9;&#9;var body: some View { &#9;&#9;&#9;&#9;NavigationView{ &#9;&#9;&#9;&#9;&#9;&#9;Form { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Section(header: Text("Search bar")){ &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;TextField("Search", text: $searchText) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.padding(7) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.background(Color(.systemGray6)) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.cornerRadius(8) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Section(){ &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;List{ &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;ForEach(sf) { item in &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Text(item.title) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;.navigationTitle("SF") &#9;&#9;&#9;&#9;} &#9;&#9;} &#9;&#9; } struct SF: Codable, Identifiable { &#9;&#9;var id: String &#9;&#9;var title: String &#9;&#9;var items: [String] } extension Bundle { &#9;func decode<T: Codable>(_ file: String) -> T { &#9;&#9; &#9;&#9;guard let url = self.url(forResource: file, withExtension: nil) else { &#9;&#9;&#9;fatalError("Failed to locate \(file) in bundle.") &#9;&#9;} &#9;&#9; &#9;&#9;guard let data = try? Data(contentsOf: url) else { &#9;&#9;&#9;fatalError("Failed to load \(file) from bundle.") &#9;&#9;} &#9;&#9; &#9;&#9;let decoder = JSONDecoder() &#9; &#9;&#9;guard let loaded = try? decoder.decode(T.self, from: data) else { &#9;&#9;&#9;fatalError("Failed to decode \(file) from bundle.") &#9;&#9;} &#9;&#9; &#9;&#9;&#9;return loaded &#9;} }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Dec ’20
Reply to Xcode requirements
You use 6 GB for Xcode alone ? In that case, yes, I fear there is a lot of swapping, which causes the slow down. In my case, a few years ago (Xcode 8 probably at the time), my iMac became really slow. I added RAM from 8 to 24 GB. Major improvement. If you extend memory, I advise you to install 32 GB. Note: on Mac 21.5", I read that memory upgrade must be done by Apple technician. Check before buying.
Dec ’20
Reply to Xcode requirements
Ok, so do you think it depends on the ram memory? and not from the hard disk? If you have 950 GB free on a total of 1000 GB, that is not a disk space issue. It is not either a processor speed issue (My iMac is 2015 and works OK with Xcode 12. So, the most likely is the RAM. And definitely, 6GB used over 8 GB (you have other processes to run as well) means you are reaching the limit and are going into (slow) swap operations. So answer is YES, I think it depends on the ram memory
Dec ’20
Reply to Instance member 'deci' cannot be used on type 'BMIView'; did you mean to use a value of this type instead?
Don't do it here, but later when you use numberFormatter: &#9;&#9;@State var deci = "3" &#9;&#9; &#9;&#9;&#9;var numberFormatter: NumberFormatter = { &#9;&#9;&#9;&#9;&#9;let nf = NumberFormatter() &#9;&#9;&#9;&#9;&#9;nf.locale = Locale.current &#9;&#9;&#9;&#9;&#9;nf.numberStyle = .decimal &#9;&#9;&#9;&#9;&#9;return nf &#9;&#9;&#9;}() &#9;&#9; &#9;&#9; @State private var height = "" &#9;&#9; @State private var weight = "" &#9;&#9; @Environment(\.presentationMode) var presentationMode &#9;&#9; var inputAfterConvertions: Double { &#9;&#9;&#9;&#9; //Use NumberFormatter to read numeric values &#9;&#9;&#9;&#9;numberFormatter.maximumFractionDigits = Int(deci) ?? 0 &#9;&#9;&#9;&#9; let hh = numberFormatter.number(from: height)?.doubleValue ?? 0 //<- &#9;&#9;&#9;&#9; let ww&#9;= numberFormatter.number(from: weight)?.doubleValue ?? 0 //<- &#9;&#9;&#9;&#9; var ris: Double = 0 &#9;&#9;&#9;&#9; if hh > 0 && ww > 0{ &#9;&#9;&#9;&#9;&#9;&#9; ris = (ww / (hh * hh)) * 10000 &#9;&#9;&#9;&#9;&#9;&#9; return ris &#9;&#9;&#9;&#9; } &#9;&#9;&#9;&#9; return 0 &#9;&#9; }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Dec ’20
Reply to List in ForEach SwiftUI
You mean, if you replace ScrollView by List ? For me it works Or do you add List inside scrollView ? &#9;&#9;&#9;&#9;ScrollView { &#9;&#9;&#9;&#9;&#9;&#9;List { Effectively, you get nothing. But why would you do it ? I remember there was an issue with SwiftUI for such a pattern. List before scroll does work &#9;&#9;&#9;&#9;List { &#9;&#9;&#9;&#9;&#9;&#9;ScrollView { But would be the interest either ?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Dec ’20
Reply to Fetch JSON Data not working
Have you checked the content you get at each step of: &#9;&#9;&#9;&#9;self.can = URLSession.shared.dataTaskPublisher(for: url) &#9;&#9;&#9;&#9;&#9;&#9;.map { $0.data } &#9;&#9;&#9;&#9;&#9;&#9;.decode(type: [User].self, decoder: JSONDecoder()) &#9;&#9;&#9;&#9;&#9;&#9;.replaceError(with: []) &#9;&#9;&#9;&#9;&#9;&#9;.eraseToAnyPublisher() &#9;&#9;&#9;&#9;&#9;&#9;.receive(on: DispatchQueue.main) &#9;&#9;&#9;&#9;&#9;&#9;.sink(receiveValue: { users in &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;self.users&#9;= users &#9;&#9;&#9;&#9;&#9;&#9;}) Who you paste code, please use Paste and Match Style, to avoid all the extra blank lines. import SwiftUI import Combine struct ContentView: View { &#9;&#9;@ObservedObject var networkController = NetworkController() &#9;&#9;@State var search: String = "" &#9;&#9;var body: some View { &#9;&#9;&#9;&#9;NavigationView{ &#9;&#9;&#9;&#9;&#9;&#9;Form{ &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Section(){ &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;TextField("Search", text: $search) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Section(){ &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;List(networkController.users.filter { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;$0.state.contains(search) } &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; , id: \.state){ user in &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Text(user.state) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;.navigationTitle("API") &#9;&#9;&#9;&#9;} &#9;&#9;} } class NetworkController: ObservableObject { &#9;&#9;private var can: AnyCancellable? &#9;&#9; &#9;&#9;let url = URL(string: "https://api.covidtracking.com/v1/states/current.json")! &#9;&#9;@Published var users = [User(state: "")] &#9;&#9; &#9;&#9;init() { &#9;&#9;&#9;&#9;self.can = URLSession.shared.dataTaskPublisher(for: url) &#9;&#9;&#9;&#9;&#9;&#9;.map { $0.data } &#9;&#9;&#9;&#9;&#9;&#9;.decode(type: [User].self, decoder: JSONDecoder()) &#9;&#9;&#9;&#9;&#9;&#9;.replaceError(with: []) &#9;&#9;&#9;&#9;&#9;&#9;.eraseToAnyPublisher() &#9;&#9;&#9;&#9;&#9;&#9;.receive(on: DispatchQueue.main) &#9;&#9;&#9;&#9;&#9;&#9;.sink(receiveValue: { users in &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;self.users&#9;= users &#9;&#9;&#9;&#9;&#9;&#9;}) &#9;&#9;} &#9;&#9; } struct User: Decodable { &#9;&#9;var state: String }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Dec ’20