Post

Replies

Boosts

Views

Activity

Reply to Adding Trailing Item to NavigationView Changes Appearance
I assume you mean navigationBarItems with trailing item. (It adds a trailing item to navigation bar.) I wanted to know why adding a trailing item messes everything up.  Not clearly documented, but the style of container may affect the default styles of content in SwiftUI. Please try specifying the listStyle explicitly: &#9;&#9;var body: some View { &#9;&#9;&#9;&#9;NavigationView { &#9;&#9;&#9;&#9;&#9;&#9;List { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;//... &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;.listStyle(InsetListStyle()) //<- &#9;&#9;&#9;&#9;&#9;&#9;.navigationBarTitle("Grades") &#9;&#9;&#9;&#9;&#9;&#9;.navigationBarItems(trailing: &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Button(action: {}) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Image(systemName: "plus") &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;) &#9;&#9;&#9;&#9;&#9;&#9;.navigationViewStyle(StackNavigationViewStyle()) &#9;&#9;&#9;&#9;} &#9;&#9;}
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Apr ’21
Reply to Question: Swiftui http request without button
Thanks for updating your code. It gets far more readable and would save readers time. (When you see extra empty lines than your original code, Edit > Paste and Match Style of Safari would work.) In your code, you put too many lines in an action closure, you should better create a method and just call it inside an action closure. struct ContentView: View { &#9;&#9; &#9;&#9;@State var username: String = "." &#9;&#9;@State var password: String = "." &#9;&#9; &#9;&#9;var body: some View { &#9;&#9;&#9;&#9;ZStack { &#9;&#9;&#9;&#9;&#9;&#9;VStack { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.onAppear { //-> Cannot infer contextual base in reference to member 'onAppear' &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;doHttpRequest() &#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;func doHttpRequest() { &#9;&#9;&#9;&#9;if 1==1 { //Do you still need this? &#9;&#9;&#9;&#9;&#9;&#9;let myUrl = URL(string: "...")! //Trailing semicolon is not needed &#9;&#9;&#9;&#9;&#9;&#9;var request = URLRequest(url: myUrl) &#9;&#9;&#9;&#9;&#9;&#9;request.httpMethod = "POST"// Compose a query string &#9;&#9;&#9;&#9;&#9;&#9;let postString = "Name=\($username)&Passwort=\($password)" //??? &#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;&#9;&#9;request.httpBody = postString.data(using: .utf8) &#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;&#9;&#9;let task = URLSession.shared.dataTask(with: request) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;(data, response, error) in &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;//Use if-let when you want to use the unwrapped value &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;if let error = error { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;print("error=\(error)") &#9;&#9;&#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;&#9;&#9;&#9;&#9;&#9;&#9;//Use guard-let when nil has no meaning and want to exit on nil &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;guard let response = response else { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;print("Unexpected nil response") &#9;&#9;&#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;// You can print out response object &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;print("response = \(response)") &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;//Let's convert response sent from a server side script to a NSDictionary object: &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;do { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;//Use guard-let when nil has no meaning and want to exit on nil &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;guard let data = data else { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;print("Unexpected nil data") &#9;&#9;&#9;&#9;&#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;&#9;&#9;//#1 `mutableContainer` has no meaning in Swift &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;//#2 Use Swift Dictionary type instead of `NSDictionary` &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;let json = try JSONSerialization.jsonObject(with: data) as? [String: Any] &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;if let parseJSON = json { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;// Now we can access value of First Name by its key &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;//Use if-let when you want to use the unwrapped value &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;if let firstNameValue = parseJSON["Name"] as? String { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;print("firstNameValue: \(firstNameValue)") &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;let dateien =&#9;firstNameValue.components(separatedBy: ",") &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;print(dateien) &#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;} catch { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;print(error) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;task.resume() &#9;&#9;&#9;&#9;} &#9;&#9;} } (I have brushed up some parts of doHttpRequest. Please see comments with //#.) You should better include the error messages when you want to ask something about codes causing errors. The error Cannot infer contextual base in reference to member 'onAppear' occurs becauseonAppear is a method classified as view modifier, which must be added to a view. In your code, there is no view directly before .onAppear. For example, if you put .onAppear to the outermost view of body, you can write it as: &#9;&#9;var body: some View { &#9;&#9;&#9;&#9;ZStack { &#9;&#9;&#9;&#9;&#9;&#9;VStack { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;//... &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;.onAppear { //This `onAppear` is added to `ZStack{...}` &#9;&#9;&#9;&#9;&#9;&#9;doHttpRequest() &#9;&#9;&#9;&#9;} &#9;&#9;}
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Apr ’21
Reply to Problem With Filter
Thanks for showing your code. Checking your dataSource methods, your UICollectionView (collections) shows allTextArr when searchBar.selectedScopeButtonIndex 0. But in your searchBar(_:textDidChange:), you update allTextArr from cPlayerArr. Generally: You need to re-fetch when selectedScopeButtonIndex is changed You need to re-filter when searchText is changed But your current searchBar(_:textDidChange:) mixes up two different things -- re-fetch and re-filter. I would write them as follows: // Array of fetched `CurrentPlayers` when `selectedScopeButtonIndex 0` var origPlayerArr = [CurrentPlayers]() func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) { updateFilteredArray(searchText: searchText) collections.reloadData() } private func updateFilteredArray(searchText: String) { let origArray: [CurrentPlayers] if searchBar.selectedScopeButtonIndex 0 { origArray = origPlayerArr } else { origArray = cPlayerArr } allTextArr = origArray.filter { player - Bool in if searchText.isEmpty { return true } else { return player.yahooName!.lowercased().contains(searchText.lowercased()) } } } func searchBar(_ searchBar: UISearchBar, selectedScopeButtonIndexDidChange: Int) { if (searchBar.selectedScopeButtonIndex == 0) { cPlayerArr.removeAll() allTextArr.removeAll() fetchAllPlayers() } else if (searchBar.selectedScopeButtonIndex == 1) { allTextArr.removeAll() fetchForwards() } else if (searchBar.selectedScopeButtonIndex == 2) { allTextArr.removeAll() fetchDefense() } else { allTextArr.removeAll() fetchGoalies() } updateFilteredArray(searchText: searchBar.text ?? "") collections.reloadData() } And modify fetch methods fetchForwards(), fetchDefense() and fetchGoalies() as: func fetchForwards() { do { let request = CurrentPlayers.fetchRequest() as NSFetchRequestCurrentPlayers let forwards = NSPredicate(format: "position CONTAINS 'RW' OR position CONTAINS 'LW' OR position CONTAINS 'C'") request.predicate = forwards self.origPlayerArr = try context.fetch(request) //- } catch { print(error) //... } } // Same for `fetchDefense()` and `fetchGoalies()`...
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’21
Reply to Anyway to remove the word 'Optional' from a website obtained from Google API?
the printed out value is: Optional("Website URL"). Assuming you get this output from print("The selected place is: \(String(describing: place.website ))"), you may need to unwrap Optional in a safe manner: if let place = place, let website = place.website { print("The selected place is: \(website)") } This is not a critical issue, but you should better use error instead of error.localizedDescription to print debugging info. if let error = error { print("An error occurred: \(error)") return } print("....\(error)") will give you more info than error.localizedDescription.
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’21
Reply to Deleting views from a stack view?
Please try this: &#9;&#9;func removeAllButtons() { &#9;&#9;&#9;&#9;let buttons = tackStack.arrangedSubviews &#9;&#9;&#9;&#9;&#9;&#9;.filter {$0 is UIButton} &#9;&#9;&#9;&#9;for button in buttons { &#9;&#9;&#9;&#9;&#9;&#9;tackStack.removeArrangedSubview(button) &#9;&#9;&#9;&#9;&#9;&#9;button.removeFromSuperview() &#9;&#9;&#9;&#9;} &#9;&#9;}
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’21
Reply to xcode
First, find the appropriate version from Xcode wiki - https://en.wikipedia.org/wiki/Xcode. Seems the latest version of Xcode which runs on High Sierra 10.13.6 is 10.1. You can download old Xcodes from More Downloads page - https://developer.apple.com/download/more/. But please remember, you need Xcode 11 or later to build an iOS app for App Store, meaning you need to upgrade your macOS (or Mac) to 10.14.4 or later to build App Store apps.
Apr ’21
Reply to Programmatically closing an app.
I was wondering the same thing about exit(0). Quite a few people say that would be rejected, Old App Store Review Guidelines had an explicit description about quitting apps which can be interpreted as apps should not quit itself, and as you found, there were some reports that apps had been rejected because of exit. I cannot find the same description in the latest App Store Review Guidelines - https://developer.apple.com/app-store/review/guidelines/ nor the latest Human Interface Guidelines - https://developer.apple.com/design/human-interface-guidelines/. You should better read them carefully (maybe you have read them several times, then once again), and you can challenge if you think it to be safe enough to use exit, with your own risk.
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’21
Reply to Can't call some functions in an ObjC category from Swift. Keep getting "Value type has no member" or "Cannot find in scope" errors.
As far as I tried, the GitHub repository you have referred lacks the right definition of protocol MYAudioTabProcessorDelegate and does not compile. Are you sure you have fixed the issue and your project compiles successfully when you remove self.player.meteringEnabled = true (and all other self.player.... parts causing the error)?
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’21
Reply to Can't call some functions in an ObjC category from Swift. Keep getting "Value type has no member" or "Cannot find in scope" errors.
Yes, my project compiles OK for me if I remove those lines that try calling fooTest() or try setting self.player.meteringEnabled Thanks for your reply. Then the issue may be different than I guessed. The Github project compiles ok It does not have any meaning if the original ObjC only project would compile or not.
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’21
Reply to App no Longer Available
Is this conclusion correct? If not, what I need to do? Partially correct. Your developing apps installed via Xcode have some fixed period of days available. If you do not want to pay for Developer Programs, you may need to update your app and re-install it using your Xcode.
Apr ’21