Post

Replies

Boosts

Views

Activity

KVO is not available in the suite UserDefaults
Hi, I am creating an AppExtension that uses ReplayKit. I want to know that ReplayKit was launched in HostApp, so I figured I could record that it was launched in the suite's UserDefaults and KVO that record in HostApp. Here is the minimal code. Xcode12.2 iPhone12 Pro iOS14.2 HostApp Code import UIKit final class ViewController: UIViewController {       @IBOutlet private weak var messageLabel: UILabel!       private let userDefaults = UserDefaults(suiteName: "app_group_id")   private let key = "key"   private var context = 0       override func viewDidLoad() {     super.viewDidLoad()     self.userDefaults?.addObserver(self, forKeyPath: self.key, options: .new, context: &self.context)   }       override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {     guard context == &self.context,        let change = change, let message = change[.newKey] as? String else { return }     self.messageLabel.text = message   }       deinit {     self.userDefaults?.removeObserver(self, forKeyPath: self.key, context: &self.context)   } } AppExtension Code import ReplayKit final class SampleHandler: RPBroadcastSampleHandler {       private let userDefaults = UserDefaults(suiteName: "app_group_id")   private let key = "key"       override func broadcastStarted(withSetupInfo setupInfo: [String : NSObject]?) {     self.userDefaults?.setValue("Broadcast Started😄", forKey: self.key)   }       override func broadcastFinished() {     self.userDefaults?.setValue("Broadcast Finished😴", forKey: self.key)   } } When delivering in ReplayKit with HostApp running, I expected the labels to change. But nothing changed. How do I do KVO in the suite UserDefaults? Thanks for any help.
1
0
761
Dec ’20
LazyVGrid does not render as expected when animated.
Hello. When the LazyVGrid display area is expanded by hiding the View while animating it, the additional View is drawn without animation. Below is a sample code. When the orange color is hidden by pressing a button, the blue and green colors that appear from the bottom of the screen are drawn without animation. This phenomenon does not occur in Canvas. It occurs in the simulator. Is there any way to avoid this phenomenon? Thanks. import SwiftUI struct PlaygroundView: View {   @State var isOrangeHidden = false   let columns = [     GridItem(.fixed(100), spacing: 16),     GridItem(.fixed(100), spacing: 16)   ]       var body: some View {     ScrollView {       Button {         isOrangeHidden.toggle()       } label: {         Text("toggle isOrangeHidden")       }               VStack {         Color.red           .frame(height: 100)         if !isOrangeHidden {           Color.orange             .frame(height: 100)         }       }               LazyVGrid(columns: columns) {         ForEach(0..<100, id: \.self) { index in           if index % 4 == 0 || index % 4 == 3 {             Color.green               .frame(height: 100)           } else {             Color.blue               .frame(height: 100)           }         }       }     }     .padding()     .animation(.easeInOut(duration: 0.2), value: isOrangeHidden)   } } struct PlaygroundView_Previews: PreviewProvider {   static var previews: some View {     PlaygroundView()   } }
0
0
954
Aug ’22
Unable to preview SwiftUI targeting framework
Hi, Using an Apple silicon mac, I am unable to preview the SwiftUI targeting the framework in a project with EXCLUDED_ARCHS[sdk=iphonesimulator*] set to arm64. Sample project The following log seems to indicate that the x86_64 binary was built according to the build settings, but what was actually needed was the arm64 binary. I would like to know if anyone knows how to solve this problem. Thanks. PotentialCrashError: Update failed XCPreviewAgent may have crashed. Check ~/Library/Logs/DiagnosticReports for any crash logs from your application. ================================== |  RemoteHumanReadableError |   |  LoadingError: failed to load library at path "/Users/me/Library/Developer/Xcode/DerivedData/SwiftUIQuestionSample-bqvuazkgqqnpkbdvedgtbpnnzgnw/Build/Intermediates.noindex/Previews/UIComponents/Products/Debug-iphonesimulator/UIComponents.framework/UIComponents": Optional(dlopen(/Users/me/Library/Developer/Xcode/DerivedData/SwiftUIQuestionSample-bqvuazkgqqnpkbdvedgtbpnnzgnw/Build/Intermediates.noindex/Previews/UIComponents/Products/Debug-iphonesimulator/UIComponents.framework/UIComponents, 0x0000): tried: '/Users/me/Library/Developer/Xcode/DerivedData/SwiftUIQuestionSample-bqvuazkgqqnpkbdvedgtbpnnzgnw/Build/Intermediates.noindex/Previews/UIComponents/Products/Debug-iphonesimulator/UIComponents.framework/UIComponents' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/Users/me/Library/Developer/Xcode/DerivedData/SwiftUIQuestionSample-bqvuazkgqqnpkbdvedgtbpnnzgnw/Build/Intermediates.noindex/Previews/UIComponents/Products/Debug-iphonesimulator/UIComponents.framework/UIComponents' (errno=2), '/Users/me/Library/Developer/Xcode/DerivedData/SwiftUIQuestionSample-bqvuazkgqqnpkbdvedgtbpnnzgnw/Build/Intermediates.noindex/Previews/UIComponents/Products/Debug-iphonesimulator/UIComponents.framework/UIComponents' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/UIComponents.framework/UIComponents' (errno=2)) |   |  ================================== |   |  |  MessageSendFailure: Message send failure for <ServiceMessage 3: update>
0
0
760
Jan ’23
How to test against non-iOS17 SDKs with Xcode15 series command line tools?
Hello. I would like to perform UnitTest using the xcodebuild command in Xcode15 series, but it does not work. Specifically, I want to run the test on an iPhone 14 with iOS 16.4 simulator environment, but for some reason it fails due to a certificate mismatch. For some reason I don't want to test on iOS17, so I specify iOS16.4. The following is a pseudo-command to run the test. Thank you! xcodebuild -workspace AppWorkspace.xcworkspace -scheme App -sdk iphonesimulator -destination "platform=iOS Simulator,name=iPhone 14,OS=16.4" -configuration TestConfiguration test
1
0
632
Sep ’23