Post

Replies

Boosts

Views

Activity

Reply to TextField with NumberFormatter, bound to Decimal property with Xcode > 13 beta 2.
An interesting example. In my opinion, this is a bug of iOS 13 beta 3+ and you should better send a bug report soon. What must be changed in the code so that entered numerical values are stored in the Decimal property again? As far as I tried, creating a Binding String <-> Decimal seemed nearly working: private let decimalFormatter: NumberFormatter = { // let formatter = MyNumberFormatter() let formatter = NumberFormatter() formatter.numberStyle = .decimal formatter.generatesDecimalNumbers = true return formatter }() struct DecimalBindingView: View { @Binding var model: Model var stringBinding: Binding<String> init(model: Binding<Model>) { _model = model stringBinding = Binding(get: { decimalFormatter.string(for: model.wrappedValue.decimalQuantity) ?? "" }, set: { if let decimal = decimalFormatter.number(from: $0) as? NSDecimalNumber { model.wrappedValue.decimalQuantity = decimal as Decimal } }) } var body: some View { Form { Section { Label { Text("This text field does not work correctly. \nIt doesn't write the value back to the property when the field loses focus or you click Enter.") } icon: { Image(systemName: "xmark.circle").foregroundColor(Color.red).scaleEffect(1.4) } .lineLimit(10) TextField("Input a number of type decimal…", text: stringBinding) } Section { TextField( "Sample field, so you can leave the other field", text: $model.someText) } } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’21
Reply to Title and Description ShareSheet
You may use UIActivityItemSource with LPLinkMetadata. Prepare a class inheriting UIActivityItemSource somewhere in your project: import LinkPresentation class MyActivityItemSource: NSObject, UIActivityItemSource { var title: String var text: String init(title: String, text: String) { self.title = title self.text = text super.init() } func activityViewControllerPlaceholderItem(_ activityViewController: UIActivityViewController) -> Any { return text } func activityViewController(_ activityViewController: UIActivityViewController, itemForActivityType activityType: UIActivity.ActivityType?) -> Any? { return text } func activityViewController(_ activityViewController: UIActivityViewController, subjectForActivityType activityType: UIActivity.ActivityType?) -> String { return title } func activityViewControllerLinkMetadata(_ activityViewController: UIActivityViewController) -> LPLinkMetadata? { let metadata = LPLinkMetadata() metadata.title = title metadata.iconProvider = NSItemProvider(object: UIImage(systemName: "text.bubble")!) //This is a bit ugly, though I could not find other ways to show text content below title. //https://stackoverflow.com/questions/60563773/ios-13-share-sheet-changing-subtitle-item-description //You may need to escape some special characters like "/". metadata.originalURL = URL(fileURLWithPath: text) return metadata } } And use it like this: let title = "Jokes Are Us Diagnostics:" let text = "Some Text" // set up activity view controller let textToShare: [Any] = [ MyActivityItemSource(title: title, text: text) ] let activityViewController = UIActivityViewController(activityItems: textToShare, applicationActivities: nil) activityViewController.popoverPresentationController?.sourceView = self.view // so that iPads won't crash // exclude some activity types from the list (optional) activityViewController.excludedActivityTypes = [ UIActivity.ActivityType.airDrop ] // present the view controller self.present(activityViewController, animated: true, completion: nil) As far as I tried, this may not produce the expected result if you add other items into textToShare.
Topic: UI Frameworks SubTopic: UIKit Tags:
Aug ’21
Reply to View body is called although its @Binding has not changed
we’d expect that its body is called when the value changes. Unfortunately, that is a wrong expectation. SwiftUI may call body at any time needed, for example any of the @State variables of the outer view change. Is there any way to avoid this behaviour that can ultimately lead to performance issues? You may need to construct your views as will not lead performance issues, or you can go back to UIKit world.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’21
Reply to @AppStorage with Date in SwiftUI
Your #1 is locale-dependent. When user change the Language settings of the device, the saved date would not be able to be retrieved. Also, it lacks time information. Your #2 lacks sub-second information. Re-read value may not be exactly the same as was when saved.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’21
Reply to Need Help Transfer Data From Button
Okay I can give you the favcell code it's a custom cell, the segue to HighlightsVC is put where the button is. Thanks for showing your code and clarifying. I'm also counting on this: I have to get rid of the button action and do a segue with storyboard. As you are connecting the segue from the button, insisting on using tableView(_:willSelectRowAt:) does not make sense and you can remove it. Please try the following prepare(for:sender:) and tell us what you get. override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if segue.identifier == "hs" { print("this is the segue destination: \(segue.destination)") if let button = sender as? UIButton { var currentView: UIView = button while let parentView = currentView.superview { if let cell = parentView as? FavCell { let selectedNameInCell = cell.name.text print("name being transferred is \(selectedNameInCell)") if let destinationController = segue.destination as? HighlightsVC, let destName = selectedNameInCell { destinationController.playerName = destName } break } currentView = parentView } } else { print("The segue is not from UIButton") } } }
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’21
Reply to TextField with NumberFormatter, bound to Decimal property with Xcode > 13 beta 2.
An interesting example. In my opinion, this is a bug of iOS 13 beta 3+ and you should better send a bug report soon. What must be changed in the code so that entered numerical values are stored in the Decimal property again? As far as I tried, creating a Binding String <-> Decimal seemed nearly working: private let decimalFormatter: NumberFormatter = { // let formatter = MyNumberFormatter() let formatter = NumberFormatter() formatter.numberStyle = .decimal formatter.generatesDecimalNumbers = true return formatter }() struct DecimalBindingView: View { @Binding var model: Model var stringBinding: Binding<String> init(model: Binding<Model>) { _model = model stringBinding = Binding(get: { decimalFormatter.string(for: model.wrappedValue.decimalQuantity) ?? "" }, set: { if let decimal = decimalFormatter.number(from: $0) as? NSDecimalNumber { model.wrappedValue.decimalQuantity = decimal as Decimal } }) } var body: some View { Form { Section { Label { Text("This text field does not work correctly. \nIt doesn't write the value back to the property when the field loses focus or you click Enter.") } icon: { Image(systemName: "xmark.circle").foregroundColor(Color.red).scaleEffect(1.4) } .lineLimit(10) TextField("Input a number of type decimal…", text: stringBinding) } Section { TextField( "Sample field, so you can leave the other field", text: $model.someText) } } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Aug ’21
Reply to Please tell me why licenceUrl is nil???
Can you explain what the app Bundle does not work more precisely? What do you expect with your code? What actually happens with your code?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Aug ’21
Reply to Please tell me why licenceUrl is nil???
Sorry, but you have not answered to What do you expect with your code?, so the problem is not clear enough. Anyway, I will write an answer based on my guess.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Aug ’21
Reply to Please tell me why licenceUrl is nil???
I guess you have not added the folder textFiles successfully. If the folder is added to the project, it is shown in a bluish color, not dark-yellowish.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Aug ’21
Reply to Swift, iOS and C++ exceptions
Can this be done ? NO. You may need to write some Objective-C++ code to interface your C++ apis to swift.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Aug ’21
Reply to Is there iOS custom SDK for Razorpay
I do not know about Razorpay, but it seems not to be a framework of Apple's. You should better find the right channel to ask things about that.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Aug ’21
Reply to Developer Account and App Store Developer?
I want App Store to show my team or company name ? Then your team or company needs to be a member of Enterprise Apple Developer Program. When you enter the Team of the Enterprise Apple Developer Program, you can use it as Team in your Xcode.
Replies
Boosts
Views
Activity
Aug ’21
Reply to ITMS-90809: Deprecated API Usage - Apple will stop accepting submissions of apps that use UIWebView APIs
If you are using some third party libraries, any of them might be using UIWebView. You should better check this article and see if your archived binary (not project sources) contains UIWebView or not.
Replies
Boosts
Views
Activity
Aug ’21
Reply to Develop in Swift build a bouncy ball game
on lines 78, 80, and 121 What are lines 78, 80 and 121? Can someone explain my error? Can you show us the error you get?
Topic: Business & Education SubTopic: General Tags:
Replies
Boosts
Views
Activity
Aug ’21
Reply to Title and Description ShareSheet
You may use UIActivityItemSource with LPLinkMetadata. Prepare a class inheriting UIActivityItemSource somewhere in your project: import LinkPresentation class MyActivityItemSource: NSObject, UIActivityItemSource { var title: String var text: String init(title: String, text: String) { self.title = title self.text = text super.init() } func activityViewControllerPlaceholderItem(_ activityViewController: UIActivityViewController) -> Any { return text } func activityViewController(_ activityViewController: UIActivityViewController, itemForActivityType activityType: UIActivity.ActivityType?) -> Any? { return text } func activityViewController(_ activityViewController: UIActivityViewController, subjectForActivityType activityType: UIActivity.ActivityType?) -> String { return title } func activityViewControllerLinkMetadata(_ activityViewController: UIActivityViewController) -> LPLinkMetadata? { let metadata = LPLinkMetadata() metadata.title = title metadata.iconProvider = NSItemProvider(object: UIImage(systemName: "text.bubble")!) //This is a bit ugly, though I could not find other ways to show text content below title. //https://stackoverflow.com/questions/60563773/ios-13-share-sheet-changing-subtitle-item-description //You may need to escape some special characters like "/". metadata.originalURL = URL(fileURLWithPath: text) return metadata } } And use it like this: let title = "Jokes Are Us Diagnostics:" let text = "Some Text" // set up activity view controller let textToShare: [Any] = [ MyActivityItemSource(title: title, text: text) ] let activityViewController = UIActivityViewController(activityItems: textToShare, applicationActivities: nil) activityViewController.popoverPresentationController?.sourceView = self.view // so that iPads won't crash // exclude some activity types from the list (optional) activityViewController.excludedActivityTypes = [ UIActivity.ActivityType.airDrop ] // present the view controller self.present(activityViewController, animated: true, completion: nil) As far as I tried, this may not produce the expected result if you add other items into textToShare.
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Aug ’21
Reply to View body is called although its @Binding has not changed
we’d expect that its body is called when the value changes. Unfortunately, that is a wrong expectation. SwiftUI may call body at any time needed, for example any of the @State variables of the outer view change. Is there any way to avoid this behaviour that can ultimately lead to performance issues? You may need to construct your views as will not lead performance issues, or you can go back to UIKit world.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Aug ’21
Reply to TextField with multiple lines in Swift UI
If your app is targeting iOS 14+, you can use TextEditor instead of TextField. Do you have any reason you cannot use it?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Aug ’21
Reply to @AppStorage with Date in SwiftUI
Your #1 is locale-dependent. When user change the Language settings of the device, the saved date would not be able to be retrieved. Also, it lacks time information. Your #2 lacks sub-second information. Re-read value may not be exactly the same as was when saved.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Aug ’21
Reply to Need Help Transfer Data From Button
Okay I can give you the favcell code it's a custom cell, the segue to HighlightsVC is put where the button is. Thanks for showing your code and clarifying. I'm also counting on this: I have to get rid of the button action and do a segue with storyboard. As you are connecting the segue from the button, insisting on using tableView(_:willSelectRowAt:) does not make sense and you can remove it. Please try the following prepare(for:sender:) and tell us what you get. override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if segue.identifier == "hs" { print("this is the segue destination: \(segue.destination)") if let button = sender as? UIButton { var currentView: UIView = button while let parentView = currentView.superview { if let cell = parentView as? FavCell { let selectedNameInCell = cell.name.text print("name being transferred is \(selectedNameInCell)") if let destinationController = segue.destination as? HighlightsVC, let destName = selectedNameInCell { destinationController.playerName = destName } break } currentView = parentView } } else { print("The segue is not from UIButton") } } }
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Aug ’21
Reply to JSON from inputStream
Can you show a complete code to reproduce the issue?
Topic: App & System Services SubTopic: General Tags:
Replies
Boosts
Views
Activity
Aug ’21