Post

Replies

Boosts

Views

Activity

Reply to Make a button click update the state var in a text field
How do I make it so whenever I click the save button, the value in the text field gets passed to state var number and displaying it without the user having to press enter ? One possible solution may be giving up using NumberFormatter. struct ContentView: View { 		@State var number = 0 		@State var numberText: String = "0" 		var body: some View { 				Text("\(number)") 				TextField("enter number", text: $numberText) 				Button(action: { 						number = Int(numberText) ?? 0 				}) { 						Text("save") 				} 		} }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Dec ’20
Reply to Passing a Value ($0) to the State Var
Seems to be the same issue as in this thread - https://developer.apple.com/forums/thread/669265. You just needs to clarify what is $0 in your code. &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;//... &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;ForEach((0...6), id: \.self) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;index in //<- Declare the argument of closure explicitly &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;//↓ And use `index` instead of `$0` below &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Button(buttonTitles[index] ?? "") { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;eventPresented = true &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;selectedEventIndex = index //<- &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.foregroundColor(titleColors[index]) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.overlay(Text(eventNumbers[index] ?? "").font(.footnote).foregroundColor(.blue).offset(x: -16, y: -16)) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.buttonStyle(BorderlessButtonStyle()) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.frame(width: 48, height: 48, alignment: .center) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.background(RoundedRectangle(cornerRadius: 2) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.fill(fillColors[index]) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.shadow(color: shadowColors[index], radius: 2, x: 0, y: 0) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.sheet(isPresented: $eventPresented) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;EventView(eventVisible: self.$eventPresented, valueFromParent: self.$selectedEventIndex) &#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;//... Closure Expressions - https://docs.swift.org/swift-book/LanguageGuide/Closures.html#ID95 > Closure Expression Syntax Closure expression syntax has the following general form: { (parameters) -> return type in &#9;&#9;statements } Seems you are too accustomed to use Shorthand Argument Names.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Dec ’20
Reply to How can I install the full Xcode for High Sierra (10.12.6)
I'm not sure what you mean by the full. But you can download the latest version of Xcode from the More Downloads page - https://developer.apple.com/download/more/. You should better check which version is the latest for High Sierra, visiting Xcode wiki - https://en.wikipedia.org/wiki/Xcode. (Seems 10.1 is the latest for High Sierra. You may need to upgrade your macOS to 10.13.6 if not yet.) Please remember, you need to use Xcode 11 (comes with iOS SDK 13) or later to build an iOS app for App Store. Meaning you need a Mac capable of running newer macOS to build apps for App Store.
Dec ’20
Reply to Too Complex To Check Code in Reasonable Time?
But what can I do in my case?  Your code shown lacks many things: buttonTitles, titleColors, eventNumbers, fillColors, shadowColors and weekIndex. That unable to type-check may occur when there is some primitive errors in such declarations. I cannot reproduce the issue with your current code shown filling missing parts by guess. Please enough code to reproduce the issue.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Dec ’20
Reply to Constraint Layout No Longer Available
Previously created view controllers still show "Inferred (Constraints)" and "Autoresizing Mask" as the available options. Previously there were two different options Can you clarify what you mean by previously? Using an old Xcode? Or with exactly the same Xcode some time before? I am unable to use auto layout on any new view controller in my storyboard. For me, adding constraints to the root view does not make sense. Can you explain what sort of constrains you were adding?
Topic: UI Frameworks SubTopic: UIKit Tags:
Dec ’20
Reply to Xcode 12 installed size differs on 2 Macs
The installed sizes are wildly different on the two Macs, Can you tell us how you have checked the installed sizes? If you have checked only the size shown in Finder, it may be just a problem of Finder. Can this possibly be correct? Very unlikely. The sizes you have shown (MacBook Air) is smaller than the sizes of .xip files. Or can I expect those on the Air to have problems as soon as I try to do serious work with them? Not sure, under the currently shown info.
Dec ’20
Reply to How do I use reserved keyword `Type` in Swift?
An interesting example. My best recommendation as for now is that avoid using the identifier Type and send a bug report to bugs.swift.org . I have no choice. If you mean you cannot change the identifier Type, typealias might be a workaround for problem 1. typealias Type = ReservedKeyword.`Type` let type = Type(rawValue: 1) For problem 2, you can use non-prefixed type name: &#9;&#9;public required init(from decoder: Decoder) throws { &#9;&#9;&#9;&#9;let container = try decoder.container(keyedBy: CodingKeys.self) &#9;&#9;&#9;&#9;// problem2 &#9;&#9;&#9;&#9;self.type = try container.decode(`Type`.self, forKey: .type) &#9;&#9;} I'm not sure such workarounds would work in all future versions of Swift compilers. Better send the bug report soon.
Topic: Programming Languages SubTopic: Swift Tags:
Dec ’20
Reply to i don't get data from my server
this is the data that I should receive The outermost structure of the data is JSON array as represented with [ and ]. So, you need to pass an Array type to decode. At least, you need to change line 22 ... 34 of getData() as follows: &#9;&#9;&#9;&#9;&#9;&#9;var result : [Profile]? &#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;&#9;&#9;do { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;result = try JSONDecoder().decode([Profile].self, from: data) &#9;&#9;&#9;&#9;&#9;&#9;} catch { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;print("failed to convert\(error)") &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;&#9;&#9;guard let jsonArray = result else{ &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;return &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;&#9;&#9;for json in jsonArray { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;print(json.id) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;print(json.profileName) &#9;&#9;&#9;&#9;&#9;&#9;} You also may need to check things as shown in Claude31's reply. The term doesn't work does not work when telling what's happening with your code.
Topic: Programming Languages SubTopic: Swift Tags:
Dec ’20
Reply to i don't get data from my server
it doesn't crash but hi skips every code after line 22 the URLSession  (Sorry, I do not understand what you mean by hi...) Can you tell us how you have checked that every code after line 22 is skipped? (Have you put breakpoint somewhere?) What's shown in the debug console? (Are you activated the debug console?)
Topic: Programming Languages SubTopic: Swift Tags:
Dec ’20
Reply to i don't get data from my server
This what i get in the console  I'm afraid it is the info shown in the variables view in the left side of the debug area. To activate the debug console, (from the main menu bar of Xcode)View > Debug Area > Activate Console. Have you really done it? I have also used a breakpoint by the URLSeeion but I click on step into then hi send me to resume() function That is the right behavior of Xcode debugger when working with asynchronous code. You cannot go into the completion handler using Step Into. You need to put a breakpoint inside the completion handler. Try putting a breakpoint at the line guard let data = data,error == nil else{. One more. My server use http requset not https  To communicate with http servers, you need a proper ATS settings in your Info.plist. Have you done it?
Topic: Programming Languages SubTopic: Swift Tags:
Dec ’20