Post

Replies

Boosts

Views

Activity

How to present a view with modal animation programmatically
I have a framework that will be consumed by other developers to develop the app. I designed a view using SwiftUI in that framework and wanted to present that view with model animation programatically from the framework. There are many sample that shows how to present a view with modal animation associated with button tap. Can anyone let me know how to present a view modal programmatically?
0
0
430
Jul ’21
Present SwiftUI without tap
I wanted to present an View with modal animation full screen on top the the existing view/viewcontroller programmatically(without button tap or tap gesture). Is it possible to present a view without button tap/tap gesture?
2
0
1.1k
Jul ’21
DataFlow from Swift to SwfitUI
I have the business logic in Swift class and built UI using SwiftUI. Below the high level code that shows how SwiftUI and its subview receives the data from Swift. Please let me know if its correct approach class SwiftClass{     var score = "1"     func A () {}          func B () {         // score will get updated frequently         let scoreModal =  ScoreUIViewModel()         let scoreUI: ScoreUI = ScoreUI(showModal: .constant(true), scoreUIViewModel: scoreModal)         DispatchQueue.main.async {             scoreUI.displayScoreUI()         }        // score getting updated from another class         scoreModal.score = score // score getting updated from another class         score  = "2"         scoreModal.score = "2" // score getting updated from another class         score  = "3"         scoreModal.score = "3" // score getting updated from another class        score  = "4"         scoreModal.score = "4"      .......              } } import SwiftUI class ScoreUIViewModel: Observable {     @Published score: String } struct ScoreUI: View {     @State var scoreUIViewModel: ScoreUIViewModel     func displayScoreUI() {         let hostController = UIHostingController(rootView: ScoreUI())         hostController = .overCurrentContext         topViewController()!.present(hostController, animated: true, completion: nil)     }.environmentObject(scoreUIViewModel)      } struct ScoreText: View {     @EnvironmentObject var scoreUIViewModel: ScoreUIViewModel     Text(score).foregroundColor(.green) }
3
0
773
Jul ’21
Passing delegate/protocol as function parameter
public protocol UploadDelegate: AnyObject {} class NetworkManager: UploadDelegate {} class A { B().abc(uploadDelegate:NetworkManager() ) } class B { func abc (uploadDelegate: UploadDelegate) { C().efg(uploadDelegate:uploadDelegate ) } } class C { func efg (uploadDelegate: UploadDelegate) { D().hij(uploadDelegate:uploadDelegate ) } } class D { func hij (uploadDelegate: UploadDelegate) { uploadDelegate.func() } } Can we pass the protocol/delegate as a func parameter? If yes, I believe its a weak property.
0
0
506
Jul ’21
Removing folder from .app
I am using "Excluded Source File Names" in Xcode build settings to remove a folder from IPA. The given relative path is correct but for some reason, the folder that needs to be excluded is still exists in the .app file. Any idea why Excluded Source File Names is not working. The folder that I am trying to remove is listed under "Copy Bundle Resources" Here is the path "$(SRCROOT)/../foldera/folderb/foldertoberemoved"
1
0
1.3k
Jul ’21
Passing Data to ViewModal
class A { func processData { let viewModel: ViewModal = ViewModal() let viewController = ViewController() viewController.displayUI(viewModel) .... .... .... .... viewModel.imageName = "abcd" .... .... .... .... viewModel.imageName = "efg" .... .... .... .... viewModel.imageName = "hij" } } class ViewController { func displayUI (viewModal: ViewModal){ let contentView = ContentView(viewModal: viewModal).environmentObject(self) // present contentView } } class ViewModal { @Published var imageName: String = ""   @Published var label: String = "" // string formatting } struct ContentView: View {  @State var viewModel: ViewModal  @EnvironmentObject var viewController: ViewController  var body: some View { } } Can class A directly access ViewModal or it should pass the data to ViewController and ViewController set the data in ViewModal
0
0
834
Jul ’21
Cannot convert value of type 'some View' to specified type ‘ContentView'
func displayUI () { let hostingController = UIHostingController(rootView: ContentView(ViewModel: contentViewModal).environmentObject(self)) } Above code works fine. I attempted to make the hostingController as instance variable instead of local variable and declared the hostingController outside of display function like this lazy var hostingController: UIHostingController = UIHostingController(rootView: ContentView()) and so I removed let keyword func displayUI () {  hostingController = UIHostingController(rootView: ContentView(ViewModel: contentViewModal).environmentObject(self)) } Once I remove the let keyword I started getting this error. Cannot convert value of type 'some View' to specified type ‘ContentView' Any idea why I am getting this error after removing let keyword declared before hostingController variable?
0
0
710
Aug ’21
How to wait until an object is removed from Array
I have declared an NSMutableArray and the count should not exceed 100. If some one calls addObject method to add an item to that array when the count is 100 then that method call should not be executed until someone removes an item so that count will go down below 100. Can we use semaphore or group dispatch for signaling or mutex/NSLock is recommended.
8
0
1.4k
Sep ’21
Concurrency
What is the best way to print in the order for the given implementation (void) print:(NSString*) str while(true) { NSLog(@“%@”, str); } } [self print:@“123”]; [self print:@“ABC”]; [self print:@“456”]; [self print:@“DEF”]; output should be printing in the order continuously 123 ABC 456 DEF 123 ABC 456 DEF … … …
2
0
747
Oct ’21