Post

Replies

Boosts

Views

Activity

Reply to Create AVPlayer instance from Data (rather than URL)?
I came up with the following solution to dynamically load Assets from Data after reading a thread on StackOverflow : import Foundation import AVFoundation #if os(macOS) import AppKit #else import UIKit #endif // Don't forget to set the File Type field in the asset catalog to the correct UTI string: com.apple.quicktime-movie extension NSDataAsset:AVAssetResourceLoaderDelegate{ @objc public func resourceLoader(_ resourceLoader: AVAssetResourceLoader, shouldWaitForLoadingOfRequestedResource loadingRequest: AVAssetResourceLoadingRequest) -> Bool { if let infoRequest = loadingRequest.contentInformationRequest{ infoRequest.isEntireLengthAvailableOnDemand = true infoRequest.contentType = typeIdentifier infoRequest.contentLength = Int64(data.count) infoRequest.isByteRangeAccessSupported = true #if DEBUG print(infoRequest) #endif } if let dataRequest = loadingRequest.dataRequest{ #if DEBUG print(dataRequest) #endif dataRequest.respond(with: data.subdata(in:Int(dataRequest.requestedOffset) ..< Int(dataRequest.requestedOffset) + dataRequest.requestedLength)) loadingRequest.finishLoading() return true } return false } } extension AVURLAsset{ public convenience init?(_ dataAsset:NSDataAsset){ guard let name = dataAsset.name.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed), let url = URL(string:"NSDataAsset://\(name))") else {return nil} self.init(url:url) // not really used! self.resourceLoader.setDelegate(dataAsset, queue: .main) // Retain the weak delegate for the lifetime of AVURLAsset objc_setAssociatedObject(self, "AVURLAsset+NSDataAsset", dataAsset, .OBJC_ASSOCIATION_RETAIN) } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Dec ’23
Reply to Document Picker does not work on device
On device your App runs in the sandbox, in the simulator there are no file access restrictions: You have to request access to files in certain directories using code similar to this: _ = url.startAccessingSecurityScopedResource() // your file access here url.stopAccessingSecurityScopedResource() https://developer.apple.com/documentation/foundation/nsurl/1417051-startaccessingsecurityscopedreso
Topic: UI Frameworks SubTopic: UIKit Tags:
Nov ’23
Reply to Language settings for back Button
This seems to be a missing translation in iOS. It started in iOS 16, was fixed in iOS 17 betas and now unfortunately returned for 17.0. You can add a Localizable.strings file to your project containing the following text: "Back" = "Zurück";
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’23
Reply to ForEach creates Views twice
Adiitionally: Don't confuse running the body with "view creation". Running the body does not really show anything yet.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Apr ’24
Reply to Using SwiftData: Model not saved when inserting from background actor
Have a look at the following article: https://www.massicotte.org/isolation-intuition about Swift Isolation Intuition. Perhaps it will help you understand where Swift runs your code.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Apr ’24
Reply to Migrating from ObservableObject to Observable in SwiftUI but still run on older OS
Have a look at the Perception package from the point.free guys. It is a backport of the Observation tools to earlier OSs: https://github.com/pointfreeco/swift-perception
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Apr ’24
Reply to ToolbarItemGroup(placement: .topBarTrailing) draws differently since iPadOS 17.4
This was finally fixed in the release candidate of 17.4. Thank you!
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Feb ’24
Reply to .playground to .swiftpm
I think, the only way to do this is to create a new (empty) .swiftpm package and copy the files/coded across.
Replies
Boosts
Views
Activity
Feb ’24
Reply to How to watch changes on fields of `@Published FamilyActivitySelection`?
You have to keep a reference to the Cancellable returned by sink: import Combine class MyModel: ObservableObject { @Published var selection = FamilyActivitySelection() var cancellables = Set<AnyCancellable>() init() { $selection.sink { newSelection in print(newSelection) }.store(in: &cancellables) } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jan ’24
Reply to Are changes to published embedded objects really not detected in SwiftUI?
This works as intended. Try if using the new Observation helps in your case.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jan ’24
Reply to ARKit and Simulator
Unfortunately plane detection is still unsupported in the simulator. There is already a thread about this problem.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jan ’24
Reply to Create AVPlayer instance from Data (rather than URL)?
I came up with the following solution to dynamically load Assets from Data after reading a thread on StackOverflow : import Foundation import AVFoundation #if os(macOS) import AppKit #else import UIKit #endif // Don't forget to set the File Type field in the asset catalog to the correct UTI string: com.apple.quicktime-movie extension NSDataAsset:AVAssetResourceLoaderDelegate{ @objc public func resourceLoader(_ resourceLoader: AVAssetResourceLoader, shouldWaitForLoadingOfRequestedResource loadingRequest: AVAssetResourceLoadingRequest) -> Bool { if let infoRequest = loadingRequest.contentInformationRequest{ infoRequest.isEntireLengthAvailableOnDemand = true infoRequest.contentType = typeIdentifier infoRequest.contentLength = Int64(data.count) infoRequest.isByteRangeAccessSupported = true #if DEBUG print(infoRequest) #endif } if let dataRequest = loadingRequest.dataRequest{ #if DEBUG print(dataRequest) #endif dataRequest.respond(with: data.subdata(in:Int(dataRequest.requestedOffset) ..< Int(dataRequest.requestedOffset) + dataRequest.requestedLength)) loadingRequest.finishLoading() return true } return false } } extension AVURLAsset{ public convenience init?(_ dataAsset:NSDataAsset){ guard let name = dataAsset.name.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed), let url = URL(string:"NSDataAsset://\(name))") else {return nil} self.init(url:url) // not really used! self.resourceLoader.setDelegate(dataAsset, queue: .main) // Retain the weak delegate for the lifetime of AVURLAsset objc_setAssociatedObject(self, "AVURLAsset+NSDataAsset", dataAsset, .OBJC_ASSOCIATION_RETAIN) } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Dec ’23
Reply to Document Picker does not work on device
On device your App runs in the sandbox, in the simulator there are no file access restrictions: You have to request access to files in certain directories using code similar to this: _ = url.startAccessingSecurityScopedResource() // your file access here url.stopAccessingSecurityScopedResource() https://developer.apple.com/documentation/foundation/nsurl/1417051-startaccessingsecurityscopedreso
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Nov ’23
Reply to List not showing in scrollview
Because the formatting of your message and code is broken I can't be sure. Does this even compile? At least it should say id:\.self
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Nov ’23
Reply to Swift Playgrounds beta with support for iOS 17 and macOS 14 expired!
Finally(!) four weeks later the necessary update was published: https://apps.apple.com/de/app/swift-playgrounds/id908519492
Replies
Boosts
Views
Activity
Oct ’23
Reply to Language settings for back Button
This seems to be a missing translation in iOS. It started in iOS 16, was fixed in iOS 17 betas and now unfortunately returned for 17.0. You can add a Localizable.strings file to your project containing the following text: "Back" = "Zurück";
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Oct ’23
Reply to Swift Playgrounds beta with support for iOS 17 and macOS 14 expired!
iOS Version expired already a week ago though.
Replies
Boosts
Views
Activity
Sep ’23
Reply to Not able to reference classes/structs in Swift playground sources
You have to mark your struct Dummy and var name as public.
Replies
Boosts
Views
Activity
Aug ’23