Post

Replies

Boosts

Views

Activity

Why?
I wrote an app that users can create utilities using terminal commands I'm experiencing a bug that's driving me crazy: I have an array of utilities, and by extension, I made Array<Utility> and Utility RawRepresantable: Part of the declaration for Utility public init?(rawValue: String) {     guard let data = rawValue.data(using: .utf8),           let result = try? JSONDecoder().decode(Utility.self, from: data)     else { return nil }     self = result } public var rawValue: String {     var encoder = JSONEncoder()     encoder.outputFormatting = .prettyPrinted     guard let data = try? encoder.encode(self),           let result = String(data: data, encoding: .utf8)     else {         return ""     }     return result } extension for Array<Utility> extension Array: RawRepresentable where Element: Codable {     public init?(rawValue: String) {         guard let data = rawValue.data(using: .utf8),               let result = try? JSONDecoder().decode([Element].self, from: data)         else { return nil }         self = result     }          public var rawValue: String {         let encoder = JSONEncoder()         encoder.outputFormatting = .prettyPrinted guard let data = try? encoder.encode(self),               let result = String(data: data, encoding: .utf8)         else {             return "[]"         }         return result     } } And now, because of some strange SwiftUI bug (FB11401294) When I pass a binding down a view hierarchy such as List or ForEach they update weirdly. I implement an "edit" feature for my utilities so I will not directly use binding but to call a function that takes an inout of Array<Utility>, the original item, and the item after being edited: func replace(_ sequence: inout [Utility], item: Utility, with replace: Utility) {     var raw = sequence.rawValue     print(raw)     let rawReplaced = raw.replacingOccurrences(of: item.rawValue, with: replace.rawValue)     print(item.rawValue, replace.rawValue)     print(rawReplaced)     sequence = [Utility].init(rawValue: sequence.rawValue.replacingOccurrences(of: item.rawValue, with: replace.rawValue))!     print(sequence) } And the problem is it works and after implementing another completely different feature it stopped working from my debugging, the input of the function is correct and the problem is inside the function. But, as the error seems to be on this line: sequence = [Utility].init(rawValue: sequence.rawValue.replacingOccurrences(of: item.rawValue, with: replace.rawValue))! Now i have completely no idea why this works last time and won't now This line of code works completely well in playgrounds and is now freaking me out Help anyone?
1
0
1.3k
Sep ’22
WebKit Loading problem
I'm tired of opening up safari to open developer.apple.com so I'm trying to embed the website into an app, but sth is definitely wrong. It's been loading for ten mins and is still white. here's the code import SwiftUI import WebKit import UIKit struct WebViewPage : UIViewRepresentable { func makeUIView(context: Context) -> WKWebView { return WKWebView() } func updateUIView(_ uiView: WKWebView, context: Context) { let req = URLRequest(url: URL(string:"developer.apple.com")!) uiView.load(req) } } #if DEBUG struct WebViewPage_Previews : PreviewProvider { static var previews: some View { WebViewPage() } } #endif app delegate: import SwiftUI @main struct Developer_WebpageApp: App { var body: some Scene { WindowGroup { WebViewPage() } } }
Topic: Safari & Web SubTopic: General Tags:
0
0
435
Apr ’22
Issue with split(or at least I think so)
I'm trying to make an app that'll suggest a color based on a keyword the user inputs. I store prediction from the model to a [String: Double] array and then compute the output color. However, I'm stuck on two strange errors. Here's my code: extension Array where Element == [String: Double]{ func average() -> RGBList{ var returnValue = (r: 0, g: 0, b: 0) var r = 0 var g = 0 var b = 0 for key in self{ r = Int(key[0].split(",")[0]) * key[1] ... } ... } }
3
0
1.3k
May ’22
@AppStorage storing a self defined structure
How can I store a struct in @AppStorage? I've been trying struct TodoItem: Codable, Hashable, Identifiable {     var id: UUID = UUID()     var name: String = "New Todo"     var description: String = "Description here..."     var done: Bool } @AppStorage("todo") var todo: [TodoItem] = [] // No exact matches in call to initializer  Any help is appreciated🙏🙏
0
0
474
May ’22
ToolBar
I'm doing a app that needs a toolbar but it wont come out: ContentView() .toolbar {             ToolbarItem {                 Button {                     data.data.append(TodoItem())                 } label: {                     Image(systemName: "plus")                 }             }         }
1
0
688
May ’22
Settings not showing
I'm using SwiftUI on Mac Catalyst: @main struct TodoApp: App {     @StateObject private var eventData = TodoData()     var body: some Scene {         WindowGroup {             ContentView().environmentObject(eventData)         }         #if os(macOS)         Settings{             TodoSettings()         }         #endif     } }
3
0
433
May ’22
Problem
I'm trying to follow the Date Planner tutorial and the symbol picker went really weird. I changed sth, and the whole app stoped working I changed it back, it still wont work. SymbolPicker code: struct PickerView: View {     @State var item: TodoItem     @State private var showingPopover: Bool = false     var columns = Array(repeating: GridItem(.flexible()), count: 6)     var body: some View {         LazyVGrid(columns: columns){             ForEach(SymbolOptions.symbolNames, id: \.self){ symbol in                 Button {                     item.symbol = symbol                 } label: {                     Image(systemName: symbol).foregroundColor(item.color)                 }             }         }     } }
1
0
383
May ’22
@AppStorage
Still about appstorage Can a store a @StateObject in @AppStorage? I can't do this: @AppStorage("Data") // No exact matches in call to initializer  @StateObject private var Data = TodoData()
0
0
637
May ’22
NSSavePanel
I want to include a button that could export some data but I'm stuck: I want a NSSavePanel open up and when I choose the pass and click save the JSON file will appear but it didn't. code: Button {     let export = exportToJSON(toExported(data.data))     let openPanel = NSSavePanel()     openPanel.message = "Choose the exported path:"     openPanel.begin { response in         if response == .OK {             print("\(openPanel.url!)")             url = openPanel.url!             let fileManager = FileManager()             let success = fileManager.createFile(atPath: "\(url)", contents: export)             debugPrint(success)         }     } } label: {     Image(systemName: "square.and.arrow.down") }.padding().buttonStyle(.plain) console: file:///Users/xxx/Documents/Untitled false
1
0
405
May ’22
I'm in china. Is App Store Connect under repair or sth? Can't connect to the website
In Safari:
Replies
1
Boosts
0
Views
1.6k
Activity
Sep ’22
Why?
I wrote an app that users can create utilities using terminal commands I'm experiencing a bug that's driving me crazy: I have an array of utilities, and by extension, I made Array<Utility> and Utility RawRepresantable: Part of the declaration for Utility public init?(rawValue: String) {     guard let data = rawValue.data(using: .utf8),           let result = try? JSONDecoder().decode(Utility.self, from: data)     else { return nil }     self = result } public var rawValue: String {     var encoder = JSONEncoder()     encoder.outputFormatting = .prettyPrinted     guard let data = try? encoder.encode(self),           let result = String(data: data, encoding: .utf8)     else {         return ""     }     return result } extension for Array<Utility> extension Array: RawRepresentable where Element: Codable {     public init?(rawValue: String) {         guard let data = rawValue.data(using: .utf8),               let result = try? JSONDecoder().decode([Element].self, from: data)         else { return nil }         self = result     }          public var rawValue: String {         let encoder = JSONEncoder()         encoder.outputFormatting = .prettyPrinted guard let data = try? encoder.encode(self),               let result = String(data: data, encoding: .utf8)         else {             return "[]"         }         return result     } } And now, because of some strange SwiftUI bug (FB11401294) When I pass a binding down a view hierarchy such as List or ForEach they update weirdly. I implement an "edit" feature for my utilities so I will not directly use binding but to call a function that takes an inout of Array<Utility>, the original item, and the item after being edited: func replace(_ sequence: inout [Utility], item: Utility, with replace: Utility) {     var raw = sequence.rawValue     print(raw)     let rawReplaced = raw.replacingOccurrences(of: item.rawValue, with: replace.rawValue)     print(item.rawValue, replace.rawValue)     print(rawReplaced)     sequence = [Utility].init(rawValue: sequence.rawValue.replacingOccurrences(of: item.rawValue, with: replace.rawValue))!     print(sequence) } And the problem is it works and after implementing another completely different feature it stopped working from my debugging, the input of the function is correct and the problem is inside the function. But, as the error seems to be on this line: sequence = [Utility].init(rawValue: sequence.rawValue.replacingOccurrences(of: item.rawValue, with: replace.rawValue))! Now i have completely no idea why this works last time and won't now This line of code works completely well in playgrounds and is now freaking me out Help anyone?
Replies
1
Boosts
0
Views
1.3k
Activity
Sep ’22
How to prettify JSON in swift
Without dependencies on other third-party frameworks Just a function that receives a string, outputs a string and throws
Replies
2
Boosts
0
Views
1.2k
Activity
Sep ’22
Where's the Preview Variants 😂 I can't find it where it should be
It says there's an error uploading the image so I can't get a image up here in a moment EDIT AFTER RESTARTING SAFARI: Oh no still won't work
Replies
2
Boosts
0
Views
890
Activity
Jun ’22
Quick Look
Hi! I'm new to Apple developing. Could anyone please tell me how to configure a quick look for my document? Also, how to print my document? Thanks🙏
Replies
1
Boosts
0
Views
1.5k
Activity
May ’22
WebKit Loading problem
I'm tired of opening up safari to open developer.apple.com so I'm trying to embed the website into an app, but sth is definitely wrong. It's been loading for ten mins and is still white. here's the code import SwiftUI import WebKit import UIKit struct WebViewPage : UIViewRepresentable { func makeUIView(context: Context) -> WKWebView { return WKWebView() } func updateUIView(_ uiView: WKWebView, context: Context) { let req = URLRequest(url: URL(string:"developer.apple.com")!) uiView.load(req) } } #if DEBUG struct WebViewPage_Previews : PreviewProvider { static var previews: some View { WebViewPage() } } #endif app delegate: import SwiftUI @main struct Developer_WebpageApp: App { var body: some Scene { WindowGroup { WebViewPage() } } }
Topic: Safari & Web SubTopic: General Tags:
Replies
0
Boosts
0
Views
435
Activity
Apr ’22
Issue with split(or at least I think so)
I'm trying to make an app that'll suggest a color based on a keyword the user inputs. I store prediction from the model to a [String: Double] array and then compute the output color. However, I'm stuck on two strange errors. Here's my code: extension Array where Element == [String: Double]{ func average() -> RGBList{ var returnValue = (r: 0, g: 0, b: 0) var r = 0 var g = 0 var b = 0 for key in self{ r = Int(key[0].split(",")[0]) * key[1] ... } ... } }
Replies
3
Boosts
0
Views
1.3k
Activity
May ’22
@AppStorage storing a self defined structure
How can I store a struct in @AppStorage? I've been trying struct TodoItem: Codable, Hashable, Identifiable {     var id: UUID = UUID()     var name: String = "New Todo"     var description: String = "Description here..."     var done: Bool } @AppStorage("todo") var todo: [TodoItem] = [] // No exact matches in call to initializer  Any help is appreciated🙏🙏
Replies
0
Boosts
0
Views
474
Activity
May ’22
ToolBar
I'm doing a app that needs a toolbar but it wont come out: ContentView() .toolbar {             ToolbarItem {                 Button {                     data.data.append(TodoItem())                 } label: {                     Image(systemName: "plus")                 }             }         }
Replies
1
Boosts
0
Views
688
Activity
May ’22
Settings not showing
I'm using SwiftUI on Mac Catalyst: @main struct TodoApp: App {     @StateObject private var eventData = TodoData()     var body: some Scene {         WindowGroup {             ContentView().environmentObject(eventData)         }         #if os(macOS)         Settings{             TodoSettings()         }         #endif     } }
Replies
3
Boosts
0
Views
433
Activity
May ’22
Problem
I'm trying to follow the Date Planner tutorial and the symbol picker went really weird. I changed sth, and the whole app stoped working I changed it back, it still wont work. SymbolPicker code: struct PickerView: View {     @State var item: TodoItem     @State private var showingPopover: Bool = false     var columns = Array(repeating: GridItem(.flexible()), count: 6)     var body: some View {         LazyVGrid(columns: columns){             ForEach(SymbolOptions.symbolNames, id: \.self){ symbol in                 Button {                     item.symbol = symbol                 } label: {                     Image(systemName: symbol).foregroundColor(item.color)                 }             }         }     } }
Replies
1
Boosts
0
Views
383
Activity
May ’22
Still about page
I can now how define part of the about page but how about the whole? Thanks better in swiftUI
Replies
0
Boosts
0
Views
322
Activity
May ’22
@AppStorage
Still about appstorage Can a store a @StateObject in @AppStorage? I can't do this: @AppStorage("Data") // No exact matches in call to initializer  @StateObject private var Data = TodoData()
Replies
0
Boosts
0
Views
637
Activity
May ’22
NSSavePanel
I want to include a button that could export some data but I'm stuck: I want a NSSavePanel open up and when I choose the pass and click save the JSON file will appear but it didn't. code: Button {     let export = exportToJSON(toExported(data.data))     let openPanel = NSSavePanel()     openPanel.message = "Choose the exported path:"     openPanel.begin { response in         if response == .OK {             print("\(openPanel.url!)")             url = openPanel.url!             let fileManager = FileManager()             let success = fileManager.createFile(atPath: "\(url)", contents: export)             debugPrint(success)         }     } } label: {     Image(systemName: "square.and.arrow.down") }.padding().buttonStyle(.plain) console: file:///Users/xxx/Documents/Untitled false
Replies
1
Boosts
0
Views
405
Activity
May ’22
iOS1.4 + iPhone SE 1st
My iPhone SE 1st will be stuck every 30 secs or so I think it's sth because it's a second-handed one I've used Instruments but can't find anything Anyone HELP Thanks🙏
Replies
1
Boosts
0
Views
863
Activity
May ’22