Posts

Post marked as solved
1 Replies
545 Views
Hi! I've got an application that can handle json (export/import). To achieve that I created a new Document Type in the info.plist, filed the imported and exported Type Identifiers, and created a new UTType. At first I was trying on the simulator and everything worked fine. I was able to created files and store them in the File app, and then read them back. I also implemented the func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) to handle documents opened from outside the application. Now when I moved on onto a real device, I noticed that I had to test the access with guard url.startAccessingSecurityScopedResource() else { throw ImportError.accessDenied } defer { url.stopAccessingSecurityScopedResource() } but I get a weird behavior : when opening a file from File app with my app launched, everything works fine. But if I try to launch my application (previously killed) from a file in the File app, startAccessingSecurityScopedResource always returns false I tried to add the NSFileCoordinator().coordinate(readingItemAt: url, error: &error) { (url) in but I get the same behavior. I guess my files and UTType are correctly declared as I only see them from inside the `UIDocumentPickerViewController`` and from the File app, I see my application in the share sheet What am I missing here ? Thanks
Posted Last updated
.
Post not yet marked as solved
2 Replies
661 Views
Hi everyone, I'd like to create a looped animation that can be paused. I achieved it with the new phaseAnimator function, and it works well, except for the pause. I tried to use the trigger option, but it stops the loop process. I tried to use a local @State var isAnimating: Bool variable, and return something like this Circle() .phaseAnimator(States.allValues, content: { content, state in if isAnimating { // do whatever animation } else { content } }, animation: { state in guard isAnimating else { return nil } // no animation // return the desired animation for the state } For some reasons, when I stop the animation, it enters some kind of infinite loop that crashes the app. I then tried to add a pause case to my enum and return no animation and no AnimationCurve when using this mode. Same as before (crashes when pausing) Do you know how can I achieve that (pausable looped animation) ? Maybe phaseAnimation is not the way to go ? Thanks
Posted Last updated
.
Post not yet marked as solved
7 Replies
756 Views
Hi! I have a xcode workspace with first objectiveC framework (let’s call it framework#1). This framework has some singletons (+(instancetype)shared using the dispatch_once idiom. This code is pretty straight forward and used everywhere : + (instancetype)shared { static dispatch_once_t onceToken; static OGAKeyManager *instance = nil; dispatch_once(&onceToken, ^{ instance = [[self alloc] init]; }); return instance; } I have a second framework (framework#2) in Swift that uses theses singletons (the framework#1 is added as do not embeed in the framework settings). And I have an application that uses both frameworks. If I make a breakpoint inside the dispatch_once alloc/init, I see that I enter 2 times : once when the shared method is called from framework#1 and another one when it’s called from framework#2. How is that even possible ? Isn't dispatch_once supposed to handle this ? I asked chatGPT, it points out to some objC/Swift interoperability, but honestly, I don't see what I can do to make it work correctly. There is no circular dependency (framwork#2 uses framwork#1, but framwork#1 has no clue of framwork#2 existence) Maybe it has something to do with sandbox, but I don't see how can it be. Does anyone experienced some weird behavior like this ? Thanks
Posted Last updated
.
Post not yet marked as solved
1 Replies
655 Views
Hi! I'm struggling with SwiftUI previews in a very specific context. I have a workspace with a framework project (objC to make things even easier :D) that has Cocoapods dependencies, and another framework project in Swift with SwiftUI views inside. The latest framework also have dependencies with SPM and has an internal dependency to the objC framework. -- Workspace ---- ObjC framework ------ Cocoapod libs ---- SwifUI framework (that relies on the objC framework) ------ SPM libs Inside the SwiftUI framework, though the project compiles well, I can't render the SwiftUI views (I had to create them in an another completely separated project to create the Views). But now I have to link the data part that relies on the objC framework, so I cannot use an external project anymore. Here is the error (I replaced the framework name and object name for NDA reasons) : Linking failed: linker command failed with exit code 1 (use -v to see invocation) ld: warning: directory not found for option '-F/Applications/Xcode.app/Contents/SharedFrameworks-iphonesimulator' Undefined symbols for architecture x86_64: "___llvm_profile_runtime", referenced from: ___llvm_profile_runtime_user in ObjCFramework(VariousObject.o) // and many more below ... (maybe you meant: ___llvm_profile_runtime_user) ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) Basically, Xcode does not find some symbols from the objC framework though both framework compile well :-/ I found a similar post but the solution, as stated in the comments, does not work for SPM based frameworks. Had anyone even the tiniest idea on how to make SwiftUI previews work ? Thanks!
Posted Last updated
.
Post marked as solved
3 Replies
667 Views
Hi everyone ;-) Let's say I have an enum enum MyEnum { case one, two } I would like to create a function in my enum that returns a dynamic type depending on the value of the enum like this extension MyEnum { var myObject: T { switch self { case .one: return ObjectOne() case .two: return ObjectTwo() } } } But (there's always a But...), I don't want to cast the receiver like let _: ObjectOne = MyEnum.one.myObject or let _: MyEnum<ObjectOne> = .one.myObject The kind of behavior that I would really like would be a dynamic typealias (this does not work of course) extension MyEnum { typealias T = { switch self { case .one: return ObjectOne.self case .two: return ObjectTwo.self } } () } // that would allow me to write this and _ would be of type ObjectOne let _ = MyEnum.one.myObject I tried protocols with associated types and static objects instead of enums, I tried nested protocol inside enums, I can't find a way to make it work Any idea, or is this just no achievable ? Thanks 🙏
Posted Last updated
.
Post marked as solved
3 Replies
1.7k Views
I have a question regarding SwiftUI (possibly with Clean architecture issue). I made a small test project with CleanSwift (Interactor/Worker/Presenter/View basically) and my view never updates. On Appear, I call the interactor, which calls the worker (network stuff), the photos are retrieved, passed along to the presenter who call the View's delegate method displayPhotos Here is the code protocol PhotoListDisplayLogic {   func displayPhotos(viewModel: PhotoList.FetchPhotots.ViewModel) } struct PhotoListView: View {   let interactor: PhotoListBusinessLogic   @State var photos: [PhotoContainer] = []       init(interactor: PhotoListBusinessLogic) {     self.interactor = interactor   }       var body: some View {     VStack {       if photos.isEmpty {         ProgressView("Chargement...")       } else {         List(photos) { photo in           PhotoListRow(photo: photo)         }       }     }     .onAppear{       interactor.fetchPhotos(request: PhotoList.FetchPhotots.Request())     }   } } extension PhotoListView: PhotoListDisplayLogic {   func displayPhotos(viewModel: PhotoList.FetchPhotots.ViewModel) {     self.photos = viewModel.photos   } } Weirdest thing : when I assign viewModel.photos to my @State var, it never updates the @State value (I have 30 photos in viewModel.photos and self.photos.count is always empty). I read here and there that the update to the @State var must be done inside the body (which is quite a limitation). Can someone spot what's wrong with this code, I guess I'm missing the elephant in the room here :D Thanks!
Posted Last updated
.
Post marked as solved
1 Replies
971 Views
Hi everyone ;-) I work on an objc framework and we will modernize it by starting to implement new features in Swift. To do so, I'm currently writing a POC, but I encountered a weird crash. If I just add some basic swift files and call them from my objc code, I can use my xcframework easily (from a swift app for the record). But, if the swift code contains Async/Await calls (even wrapped in a completion method), it does not work. This code leads to a crash right away : @objcMembers public class SwiftChecker: NSObject {   @available(iOS 13.0.0, *)   func check() async {     let data = try? await URLSession().data(for: URLRequest(url: URL(string: "http://www.google.fr")!))     if let data {       print("Yay! ❤️ \(data.0.count)")     } else {       print("Nay 😡")     }   }       public func check(completion: @escaping (() -> Void)) {     if #available(iOS 13.0.0, *) {       Task {         await check()         completion()       }     } else {       completion()     }   } } And I call it like that (inside the framework fyi) : if (@available(iOS 13.0, *)) {       SwiftChecker* checker = [[SwiftChecker alloc] init];       [checker checkWithCompletion:^{                 }];     } I even tried a more simpler code with @objcMembers public class SwiftChecker: NSObject {   @available(iOS 13.0.0, *)   func check() {     Task {       let data = try? await URLSession().data(for: URLRequest(url: URL(string: "http://www.google.fr")!))       if let data {         print("Yay! ❤️ \(data.0.count)")       } else {         print("Nay 😡")       }     }   } } but the result is the same. I f I don't use Task, then it works :-/ I can't find any reason or literature that indicates not to use modern concurrency with objC, especially when it's wrapped into a completion block like signature. I just can't give you the crash log as it has nothing to do with the actual crash. It's just a exit with signal 6 Any help would be appreciated. Thanks!
Posted Last updated
.