Post

Replies

Boosts

Views

Activity

Reply to Xcode 13.2.1 update is stuck
Difficulties installing Xcode make us developer irritated, but one thing important is being patient and wait. I have experienced several times it took 3 hours to install recent Xcode and some report more than 6 hours. You may need to keep untouched for such a period. If you have ever tried waiting for more than 6 hours, you may try to install it by downloading .xip file. Visit the More Downloads page and download the latest Xcode.xip .This would also take as much time as App Store, but the installing process is a little more visible.
Dec ’21
Reply to Decoding JSON coming from MySQL via PHP to a complex Struct in SwiftUI
The most important part of the error message is this: CodingKeys(stringValue: "date", intValue: nil)], debugDescription: "Expected to decode Double but found a string/data instead." In your JSON text, the value for "date" is string, but in your struct, you are trying to pass the value to Date not String. What you may need is not a Numberformatter, but setting dateDecodingStrategy: final class ModelDataDepot: ObservableObject { @Published var depots = [Depot]() private let dateFormatter: DateFormatter = { let df = DateFormatter() df.dateFormat = "yyyy-MM-dd" df.locale = Locale(identifier: "en_US_POSIX") return df }() init() { let url = URL(string: "https://api.webcoders.ch/index.php")! URLSession.shared.dataTask(with: url) { (data, response, error) in if let error = error { print(error) return } guard let data = data else { print("No Data!") return } do { let decoder = JSONDecoder() decoder.dateDecodingStrategy = .formatted(self.dateFormatter) let decodedData = try decoder.decode([Depot].self, from: data) DispatchQueue.main.async { self.depots = decodedData } } catch { print("JSON-Error: \(error)") } }.resume() } }
Topic: App & System Services SubTopic: General Tags:
Dec ’21
Reply to Print something on the screen
I've created a text and I would like that the text will change on the press of the button. For example: there's a Text() witch now has written on it "text" and when I press the blue button (you can see it in my code), I want "text" to change to number "5" Thanks for showing your code. You just need to declare an @State variable to hold the content of the Text. (Defining a struct NumberView makes your code too complex, better remove it.) import SwiftUI //<- import PlaygroundSupport let columns: [GridItem] = [GridItem(.flexible()), GridItem(.flexible()), GridItem(.flexible())] struct ContentView: View { @State var outputText: String = "text" //<- var body: some View { GeometryReader { geometry in VStack { Spacer(minLength: 290) Text(outputText) //<- .font(.largeTitle) ZStack { LazyVGrid(columns: columns) { Group { Button { outputText = "\(5)" //<- } label: { ZStack { Circle() .frame(width: 90, height: 90) .foregroundColor(Color(.systemBlue)) .opacity(0.5) //.position(x: geometry.size.width/2, y: -100) Text("5") .font(.largeTitle) .bold() .foregroundColor(.black) } .frame(width: 90, height: 90) } } } } } } } } PlaygroundPage.current.setLiveView(ContentView())
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’22
Reply to Publishers.CombineLatest in SwiftUI
To utilize Combine well, you may need to know what are (or should be or can be) publisher. @State variables cannot be publishers without some additional code. To make publishers easily, you can work with ObservableObject with @Published variables: import SwiftUI import Combine class ValidateLogin { let user: String let pass: String init(user: String, pass: String) { self.user = user self.pass = pass } func validateMe() -> Bool { return user.count > 3 && pass.count > 3 } } class MyContent: ObservableObject { @Published var userText: String = "" @Published var passText: String = "" } struct ContentView: View { @StateObject var content = MyContent() @State var canSave: Bool = false @State var contentSubscriber: AnyCancellable? var body: some View { ZStack { VStack { TextField("Username", text: $content.userText) { } SecureField("Password", text: $content.passText) { } }.padding(.horizontal, 20.0) }.onAppear { self.contentSubscriber = self.content.$userText .combineLatest(content.$passText) .sink {userText, passText in let validateLogin = ValidateLogin(user: userText, pass: passText) self.canSave = validateLogin.validateMe() } } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’22
Reply to Xcode 13.2.1 update is stuck
Difficulties installing Xcode make us developer irritated, but one thing important is being patient and wait. I have experienced several times it took 3 hours to install recent Xcode and some report more than 6 hours. You may need to keep untouched for such a period. If you have ever tried waiting for more than 6 hours, you may try to install it by downloading .xip file. Visit the More Downloads page and download the latest Xcode.xip .This would also take as much time as App Store, but the installing process is a little more visible.
Replies
Boosts
Views
Activity
Dec ’21
Reply to Why can’t I open the app created in swift playground 4 on the iPad in swift playground 4 on the mac?
Are you trying to open an App project of Swift Playgrounds 4 on iPad? Then you need to use Xcode (13.2 or later), not Swift Playgrounds 4 on Mac as for now.
Replies
Boosts
Views
Activity
Dec ’21
Reply to Swift Playgrounds app
Every distribution method which Apple does not guarantee would cause any sort of troubles and you should not rely on them. If you are a member of paid Developer Program, you can add your friends as external testers on TestFlight.
Replies
Boosts
Views
Activity
Dec ’21
Reply to Text background color
.background(Color) changes all the background's color Can you clarify what is all the background's color and what is the text background color?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Dec ’21
Reply to Images don't display when orientation is changed
Can you show us a complete code to reproduce the issue?
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Dec ’21
Reply to Print something on the screen
You need to define an area to output something, maybe a Text somewhere in the View.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Dec ’21
Reply to Decoding JSON coming from MySQL via PHP to a complex Struct in SwiftUI
The most important part of the error message is this: CodingKeys(stringValue: "date", intValue: nil)], debugDescription: "Expected to decode Double but found a string/data instead." In your JSON text, the value for "date" is string, but in your struct, you are trying to pass the value to Date not String. What you may need is not a Numberformatter, but setting dateDecodingStrategy: final class ModelDataDepot: ObservableObject { @Published var depots = [Depot]() private let dateFormatter: DateFormatter = { let df = DateFormatter() df.dateFormat = "yyyy-MM-dd" df.locale = Locale(identifier: "en_US_POSIX") return df }() init() { let url = URL(string: "https://api.webcoders.ch/index.php")! URLSession.shared.dataTask(with: url) { (data, response, error) in if let error = error { print(error) return } guard let data = data else { print("No Data!") return } do { let decoder = JSONDecoder() decoder.dateDecodingStrategy = .formatted(self.dateFormatter) let decodedData = try decoder.decode([Depot].self, from: data) DispatchQueue.main.async { self.depots = decodedData } } catch { print("JSON-Error: \(error)") } }.resume() } }
Topic: App & System Services SubTopic: General Tags:
Replies
Boosts
Views
Activity
Dec ’21
Reply to Print something on the screen
I've created a text and I would like that the text will change on the press of the button. For example: there's a Text() witch now has written on it "text" and when I press the blue button (you can see it in my code), I want "text" to change to number "5" Thanks for showing your code. You just need to declare an @State variable to hold the content of the Text. (Defining a struct NumberView makes your code too complex, better remove it.) import SwiftUI //<- import PlaygroundSupport let columns: [GridItem] = [GridItem(.flexible()), GridItem(.flexible()), GridItem(.flexible())] struct ContentView: View { @State var outputText: String = "text" //<- var body: some View { GeometryReader { geometry in VStack { Spacer(minLength: 290) Text(outputText) //<- .font(.largeTitle) ZStack { LazyVGrid(columns: columns) { Group { Button { outputText = "\(5)" //<- } label: { ZStack { Circle() .frame(width: 90, height: 90) .foregroundColor(Color(.systemBlue)) .opacity(0.5) //.position(x: geometry.size.width/2, y: -100) Text("5") .font(.largeTitle) .bold() .foregroundColor(.black) } .frame(width: 90, height: 90) } } } } } } } } PlaygroundPage.current.setLiveView(ContentView())
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jan ’22
Reply to Simple ForEach gets dreaded compiler is unable to type-check this expression in reasonable time
All the lines were drawn in the proper place in my View. Please show the whole definition of the View to confirm that.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jan ’22
Reply to Xcode command Line Tool c++ bug
Visit Feedback Assistant to send a bug report to Apple.
Replies
Boosts
Views
Activity
Jan ’22
Reply to Will This Work?
Depends on many things. How many files are there? How large is each file? How the data is organized as a text?
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Jan ’22
Reply to Publishers.CombineLatest in SwiftUI
To utilize Combine well, you may need to know what are (or should be or can be) publisher. @State variables cannot be publishers without some additional code. To make publishers easily, you can work with ObservableObject with @Published variables: import SwiftUI import Combine class ValidateLogin { let user: String let pass: String init(user: String, pass: String) { self.user = user self.pass = pass } func validateMe() -> Bool { return user.count > 3 && pass.count > 3 } } class MyContent: ObservableObject { @Published var userText: String = "" @Published var passText: String = "" } struct ContentView: View { @StateObject var content = MyContent() @State var canSave: Bool = false @State var contentSubscriber: AnyCancellable? var body: some View { ZStack { VStack { TextField("Username", text: $content.userText) { } SecureField("Password", text: $content.passText) { } }.padding(.horizontal, 20.0) }.onAppear { self.contentSubscriber = self.content.$userText .combineLatest(content.$passText) .sink {userText, passText in let validateLogin = ValidateLogin(user: userText, pass: passText) self.canSave = validateLogin.validateMe() } } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jan ’22
Reply to Where to review and agree the newly updated agrement??
Have you checked this thread? https://developer.apple.com/forums/thread/693841?answerId=693782022#693782022 Make sure you are an Account Holder, and visit the App Store Connect. (Not Apple Developer site.)
Replies
Boosts
Views
Activity
Jan ’22
Reply to MIDI receive callback context
No explanation is given as to why the context pointer was removed. One possible reason may be that the block can capture the context pointer, so you have no need to get it from a parameter of callback function.
Topic: Media Technologies SubTopic: General Tags:
Replies
Boosts
Views
Activity
Jan ’22
Reply to iPhone Simulator in Swift Playgrounds
Is it possible to add iPhone simulator there? As far as I know, the answer is NO. Swift Playgrounds 4 does not have a tool to explicitly test how your app looks like in each size of devices, nor it does not have an ability to run the app on actual iPhones.
Replies
Boosts
Views
Activity
Jan ’22