Post

Replies

Boosts

Views

Activity

Reply to How to get the UIViewController instance for displaying dialog when the app starts up?
Hi OOper, Thank you for your suggestion about using Life Cycle as UIKit App Delegate. I will try it. On another hand, I found a way to get a UIViewController object from ContentView.swift file, like the code below. Is this solution Ok? or there will be issue? Thank you! import SwiftUI import MoPubSDK struct ContentView: View {     var body: some View {         return         Text("Hello, world!")             .padding()             .onAppear(){                 // for MoPub: Check whether you must show the consent dialog                 let shouldShow = MoPub.sharedInstance().shouldShowConsentDialog;                 // for MoPub: Start loading the consent dialog. This call fails if the user has opted out of ad personalization                 let myUIViewController : UIViewController = (UIApplication.shared.windows.first?.rootViewController)!                 MoPub.sharedInstance().loadConsentDialog(){ a in                     MoPub.sharedInstance().showConsentDialog(from: myUIViewController, completion: nil)                 }             }     } }
Topic: UI Frameworks SubTopic: UIKit Tags:
Aug ’21
Reply to What language is the "unbrella" keyword from?
After some reading I think I understand what is the .modulemap file for: it is for the Clang complier to support the newly introduced "module" mechanism for C-like programming languages (C, C++, Objective-C, etc.). Even though I said "module" is new, I haven't actually check when it is introduced. What I am sure is it is newer than the basic #include mechanism. One of the difference it makes is to allow separate compilation of individual modules. While the "module" mechanism is being used, the original .h files (header files) of the C-like language library can still be used, and an additional file with .modulemap extension is added to specify which header file is mapped to which module name to be consumed. The syntax of this .mdulemap file is "Module Map Language". https://releases.llvm.org/3.3/tools/clang/docs/Modules.html#module-map-language
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’21
Reply to What language is the "unbrella" keyword from?
Hi Claude31, The 3rd link you provide have some examples using the "umbrella" keyword. I will try to start understand more from there. I checked the source code of the SwiftyJSON, surprisingly it is written in Swift, even though the CocoaPods adds C code to it. https://github.com/SwiftyJSON/SwiftyJSON Thank you,
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’21
Reply to How to get the current scene of the iOS14 app developed by XCode 12 and SwiftUI?
Hi Claude31, The expression "self.view.window.windowScene" is from the Google AdMob documentation. Since I am not allowed to post the link in the form, I copy-paste the code section below together with some description. The documentation doesn't tell what "self" is, but from there I assume the view should have a "window" property. However, I cannot get it when I try to use "self" in the "body" of a View definition. vvvvvvvvvvvvvvvvvvv from Google AdMob Doc vvvvvvvvvvvvvvvvvvvvvv Set the scene in an ad request In order to receive an ad that fits a specific window, you pass the view's windowScene to the ad request. The Google Mobile Ads SDK returns an ad with valid size for that scene. (void)loadInterstitial {   GADRequest *request = [GADRequest request];   request.scene = self.view.window.windowScene;   [self.interstitial loadRequest:request]; }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Apr ’21
Reply to How to get the current scene of the iOS14 app developed by XCode 12 and SwiftUI?
Just an update of the status, for now I set the "Enable Multiple Windows" in info.plist to false, such that I don't need to get the scene for now. The original reason I want to get the scene object is because I am trying to use Google Admob in an iOS app for iPad. Since iPad by default supports multiple windows, Admob is asking me to input scene. After disabling multiple windows, AdMob is no longer asing for it. Google AdMob link is not allowed to be posted in the forum, so I cannot include it.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Apr ’21
Reply to Is there a way to pretend IP address in Xcode Device Simulator?
Thank you Claude! I changed the IP address of my Mac manually for testing the app. Even though I didn't get the expected result (seeing the popup message), but I think your answer has got to the bottom of the specific question I asked.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to Xcode: Why I need #available(iOS 14.0, *) even if the project iOS Deployment Target is 14.1?
Hi Claude31, OOPer, Thank you for pointing out what I missed. I check the individual targets and found the "iOS Deployment Target". After updating each of them to iOS 14.1, I can delete the unnecessary code now.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to How to get the UIViewController instance for displaying dialog when the app starts up?
Hi OOper, For the "UIKit App Delegate" option of Life Cycle, I found it is only available if I chose "iOS" App template for the new project. If I chose "Multiplatform" template, then there is no Life Cycle choices for me to select. Thank you!
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to How to get the UIViewController instance for displaying dialog when the app starts up?
Hi OOper, Thank you for your suggestion about using Life Cycle as UIKit App Delegate. I will try it. On another hand, I found a way to get a UIViewController object from ContentView.swift file, like the code below. Is this solution Ok? or there will be issue? Thank you! import SwiftUI import MoPubSDK struct ContentView: View {     var body: some View {         return         Text("Hello, world!")             .padding()             .onAppear(){                 // for MoPub: Check whether you must show the consent dialog                 let shouldShow = MoPub.sharedInstance().shouldShowConsentDialog;                 // for MoPub: Start loading the consent dialog. This call fails if the user has opted out of ad personalization                 let myUIViewController : UIViewController = (UIApplication.shared.windows.first?.rootViewController)!                 MoPub.sharedInstance().loadConsentDialog(){ a in                     MoPub.sharedInstance().showConsentDialog(from: myUIViewController, completion: nil)                 }             }     } }
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Aug ’21
Reply to What language is the "unbrella" keyword from?
After some reading I think I understand what is the .modulemap file for: it is for the Clang complier to support the newly introduced "module" mechanism for C-like programming languages (C, C++, Objective-C, etc.). Even though I said "module" is new, I haven't actually check when it is introduced. What I am sure is it is newer than the basic #include mechanism. One of the difference it makes is to allow separate compilation of individual modules. While the "module" mechanism is being used, the original .h files (header files) of the C-like language library can still be used, and an additional file with .modulemap extension is added to specify which header file is mapped to which module name to be consumed. The syntax of this .mdulemap file is "Module Map Language". https://releases.llvm.org/3.3/tools/clang/docs/Modules.html#module-map-language
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Aug ’21
Reply to What language is the "unbrella" keyword from?
Hi Claude31, The 3rd link you provide have some examples using the "umbrella" keyword. I will try to start understand more from there. I checked the source code of the SwiftyJSON, surprisingly it is written in Swift, even though the CocoaPods adds C code to it. https://github.com/SwiftyJSON/SwiftyJSON Thank you,
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Aug ’21
Reply to What language is the "unbrella" keyword from?
Hi Claude31, Sorry, I missed the curly braces. Yes you are right. The code should be framework module SwiftyJSON { umbrella header "SwiftyJSON.h" export * module * { export * } }
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Aug ’21
Reply to SwiftUI: memory leaks if update environment object in a view
Hi wingover, That's because I have a lot of data want to share in the application across different pages. I just made a singleton class and put all the data inside. Does that cause issue? Thank you! Sui
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
May ’21
Reply to How to get the current scene of the iOS14 app developed by XCode 12 and SwiftUI?
Hi Claude31, The expression "self.view.window.windowScene" is from the Google AdMob documentation. Since I am not allowed to post the link in the form, I copy-paste the code section below together with some description. The documentation doesn't tell what "self" is, but from there I assume the view should have a "window" property. However, I cannot get it when I try to use "self" in the "body" of a View definition. vvvvvvvvvvvvvvvvvvv from Google AdMob Doc vvvvvvvvvvvvvvvvvvvvvv Set the scene in an ad request In order to receive an ad that fits a specific window, you pass the view's windowScene to the ad request. The Google Mobile Ads SDK returns an ad with valid size for that scene. (void)loadInterstitial {   GADRequest *request = [GADRequest request];   request.scene = self.view.window.windowScene;   [self.interstitial loadRequest:request]; }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Apr ’21
Reply to How to get the current scene of the iOS14 app developed by XCode 12 and SwiftUI?
Just an update of the status, for now I set the "Enable Multiple Windows" in info.plist to false, such that I don't need to get the scene for now. The original reason I want to get the scene object is because I am trying to use Google Admob in an iOS app for iPad. Since iPad by default supports multiple windows, Admob is asking me to input scene. After disabling multiple windows, AdMob is no longer asing for it. Google AdMob link is not allowed to be posted in the forum, so I cannot include it.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Apr ’21
Reply to How to get the current scene of the iOS14 app developed by XCode 12 and SwiftUI?
Hi Claude31, The stackoverflow link shows a way that needs to inject hosting window in root ContentWindow from AppDelegate or SceneDelegate. However, in the new Multiplatform App template, there is no AppDelegate/SceneDelegate by default. Seems they are being deprecated. Is there a way to do it without AppDelegate/SceneDelegate? Thank you!
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Apr ’21
Reply to Why ForEach cannot include extra logic?
Thank you Claude31!
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Apr ’21
Reply to What is the difference between Form and VStack in SwiftUI?
Thank you! BabyJ.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Apr ’21