Post

Replies

Boosts

Views

Activity

Reply to How can i run App and Scene on ipad SwiftUI playground
In your code (when you show your code, please show all the code as text), Welcoming is an App, not a View. To use setLiveView, the target needs to be a View. And there's no support showing App or Scene as live in PlaygroundPage of the current (3.4.1) Swift Playgrounds. (Swift Playgrounds 4 is expected to come late this year.) You may need to create a view to use setLiveView. struct ContentView: View { var body: some View { TabView { Text("one") Text("tow") } } } PlaygroundPage.current.setLiveView(ContentView())
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’21
Reply to NavigationLink Issue on Device
An interesting behavior. When I tested your code on my iPhone 7 Plus (iOS 14.8.1), the links were not shown. Also tried embedding in VStack & HStack I usually use ZStack when I want some hidden NavigationLinks. NavigationView { ZStack { NavigationLink(destination: SettingsView(), tag: "Settings", selection: $selection) { EmptyView() } NavigationLink(destination: AppInfoView(), tag: "Info", selection: $selection) { EmptyView() } VStack{ GameUIView() HStack{ //... } } } } .navigationViewStyle(StackNavigationViewStyle()) //...
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’21
Reply to filter an object array based on another
It is not clear enough, but you can prepare some extension like this: extension Selected { func matches(_ option: Option) -> Bool { //↓Modify the following expression to fit for your purpose return optType == option.optType && optValue == option.optValue } } And then: Button("Options Not Selected") { let optionsNotSelected = options.filter { option in !selected.contains {$0.matches(option)} } print(optionsNotSelected) //Use `optionsNotSelected`... }
Topic: Programming Languages SubTopic: Swift Tags:
Nov ’21
Reply to Having trouble using Darwin Notifications
Have you checked the doc of CFNotificationCenterGetDarwinNotifyCenter? Discussion ... As with distributed notifications, the main thread's run loop must be running in one of the common modes (usually kCFRunLoopDefaultMode) for Darwin-style notifications to be delivered. Please try adding CFRunLoopRun(); at the end of your code: int main(int argc, const char * argv[]) { // Add Observer CFNotificationCenterAddObserver( CFNotificationCenterGetDarwinNotifyCenter(), //center NULL, //observer myCallback, //callback CFSTR("sanity_check"), //event name NULL, //object CFNotificationSuspensionBehaviorDeliverImmediately ); // Post notification 1 CFNotificationCenterPostNotification( CFNotificationCenterGetDarwinNotifyCenter(), // center CFSTR("sanity_check"), // event name NULL, //object NULL, //userinfo dictionary true ); // Post notification 2 notify_post("sanity_check"); CFRunLoopRun(); //<- return 0; }
Topic: App & System Services SubTopic: Core OS Tags:
Nov ’21
Reply to wwdc20-10073 Recipe Assistant project not working
I have built the RecipeAssistant sample project with Xcode 13.1 on macOS 11.6.1 for iPhone, and run it on iPhone 12 Pro Max (iOS 15.1). It has shown a lot of messages in the debug console but I cannot find any messages like I can't get directions using Recipe Assistant. Sorry about that. neither in the debug console or in the app. Not sure macOS Monterey 12.0.1 is affecting, but can you provide more info about what you have tried?
Topic: App & System Services SubTopic: General Tags:
Nov ’21
Reply to What's the expected performance of VNHumandBodyPoseObservation::recognizedPoint
Thanks for showing the link. Is it safe to assume once the observation has been generated, the points are cached in some structure internal to the observation? The problem is that it is not clear what you mean by cached. You should better not expect anything unless it is explicitly documented. But as far as I can see in the docs and in my experiences I have used other Vision features till now, VNHumanBodyPoseObservation is a class type, so the points held in an instance would be kept while the instance is alive. In other words, you should not expect that the points would be updated even if you performed another VNDetectHumanBodyPoseRequest. If you think this is not answering to your question, please explain what you mean by cached more precisely.
Topic: Programming Languages SubTopic: Swift Tags:
Nov ’21
Reply to SwiftUI: I keep getting this error: "Thread 1: "-[AccountBackEnd accountCompanyName]: unrecognized selector sent to instance 0x6000025aac40""
Thanks for showing the entity definition. I can eliminate one possibility with it. Another possibility causing this issue might reside in this line: @ObservedObject var accountBackEnd: AccountBackEnd = AccountBackEnd() With instantiating a Core Data entity class with .init() like AccountBackEnd(), the instance has nothing to do with the entity definition, so any sort of access to @NSManaged properties will cause the error. Isn't this line in DatabaseViewMain AccountDetailMain(accountBackEnd: accountBackEnd) should be something like this? AccountDetailMain(accountBackEnd: account)
Nov ’21
Reply to Using URLSession in Combine
First of all, you should better read this article carefully: Processing URL Session Data Task Results with Combine (You may have already read it, in such a case, read it again, carefully.) With reading the article, I would write something like this: APIClient import UIKit import Combine class APIClient: NSObject { func fetchData(urlStr: String) -> AnyPublisher<[MyModel], Never> { guard let url = URL(string: urlStr) else { let subject = CurrentValueSubject<[MyModel], Never>([]) return subject.eraseToAnyPublisher() } return URLSession.shared.dataTaskPublisher(for: url) .map { $0.data } .decode(type: [MyModel].self, decoder: JSONDecoder()) .replaceError(with: []) .eraseToAnyPublisher() } } ViewModel import Foundation import Combine class ViewModel: NSObject { @IBOutlet var apiClient: APIClient! var cancellables = Set<AnyCancellable>() func getGitData() -> AnyPublisher<[MyModel], Never> { let urlStr = "https://api.github.com/repos/ReactiveX/RxSwift/events" return apiClient.fetchData(urlStr: urlStr) } } No need to use .sink, just return the modified publisher as AnyPublisher. (You may want to use Future when you want to define another async method, but this does not seem to be the case.) Or if you want to use viewModel.dataModels somewhere in the ViewController, I would change the ViewModel as follows: import Foundation import Combine class ViewModel: NSObject { @IBOutlet var apiClient: APIClient! var cancellables = Set<AnyCancellable>() private let dataModelSubject = CurrentValueSubject<[MyModel], Never>([]) var dataModels: [MyModel] { get {dataModelSubject.value} set {dataModelSubject.send(newValue)} } func getGitData() -> AnyPublisher<[MyModel], Never> { let urlStr = "https://api.github.com/repos/ReactiveX/RxSwift/events" apiClient.fetchData(urlStr: urlStr) .sink { result in print("view model: \(result.count)") self.dataModels = result } .store(in: &cancellables) return dataModelSubject.eraseToAnyPublisher() } } This shows a little different behavior than the previous code, as CurrentValueSubject will send its initial data to subscribers. (0 seems to be the count of the initial value in your code.) In your code, you hold instances of CurrentValueSubject only as a local constant and never call send to these instance. That does not seem to be the right usage of CurrentValueSubject.
Topic: UI Frameworks SubTopic: UIKit Tags:
Nov ’21