I use loadFileRepresentation(forTypeIdentifier:completionHandler:) to load video with PHPickerViewController
What can I use load video with?
// my sample code
func loadPhoto(pickerItem: PhotosPickerItem) async throws -> Photo {
if let livePhoto = try await pickerItem.loadTransferable(type: PHLivePhoto.self) {
let photo: Photo = .init(id: pickerItem.itemIdentifier, item: livePhoto)
return photo
} else if let url = try await pickerItem.loadTransferable(type: URL.self) {
let photo: Photo = .init(id: pickerItem.itemIdentifier, item: url)
return photo
} else if let data = try await pickerItem.loadTransferable(type: Data.self) {
let photo: Photo = .init(id: pickerItem.itemIdentifier, item: data)
return photo
}
throw PhotoError.load
}
Post
Replies
Boosts
Views
Activity
NavigationLink(destination:isActive:label:) is deprecated in iOS 16
How to implement below View in iOS 16 without Deprecated?
struct ContentView: View {
@State var isPresentedDetailView = false
@State var isPresentedImageView = false
var body: some View {
NavigationStack {
List {
HStack {
Button("Name") { isPresentedDetailView.toggle() }
NavigationLink(isActive: $isPresentedDetailView) {
Text("Detail View")
} label: {
EmptyView()
}
.frame(width: 0, height: 0)
.hidden()
Image(systemName: "person")
.onTapGesture {
isPresentedImageView.toggle()
}
NavigationLink(isActive: $isPresentedImageView) {
Image(systemName: "person")
} label: {
EmptyView()
}
.frame(width: 0, height: 0)
.hidden()
}
}
}
}
}
Pick 2 Photo with PhotosPicker
Deselect 2 Photo in PhotosPicker And Done
selection(PhotosPickerItem) doesn't change
PhotosPicker(selection: $photoPickerItems,
maxSelectionCount: 0,
selectionBehavior: .ordered,
matching: nil,
preferredItemEncoding: .current,
photoLibrary: .shared()) {
Image(systemName: "photo")
}
struct ContentView: View {
@State var isPresented = false
var body: some View {
Button {
isPresented.toggle()
} label: {
Text("Button")
}
.sheet(isPresented: $isPresented) {
SubView()
}
}
}
struct SubView: View {
@State var text = ""
var body: some View {
NavigationStack {
TextEditor(text: $text)
.toolbar {
ToolbarItemGroup(placement: .bottomBar) {
Button("Click") {
}
}
ToolbarItemGroup(placement: .keyboard) {
Button("Click") {
}
}
}
}
}
}
NavigationLink in List is automatically designed.
How to set appropriate multi NavigationLink in Cell?
I don't want use ForEach in ScrollView. Because I want to use swipeActions.
struct TimelineView: View {
let tweets: [Tweet] = tweets
let users: [User] = users
var body: some View {
NavigationStack {
List(tweets) { tweet in
let user = users.first { $0.id == tweet.userID }!
NavigationLink(value: tweet) {
HStack {
NavigationLink(value: user) {
Image(systemName: "person")
.foregroundStyle(user.color)
}
VStack {
Text("@\(user.name)")
Text(tweet.text)
}
}
}
.swipeActions(edge: .leading) {
Button("Like") { }
}
}
.navigationDestination(for: Tweet.self) { tweet in
TweetDetailView(tweet: tweet)
}
.navigationDestination(for: User.self) { user in
UserDetailView(user: user)
}
}
}
}
back with dismiss(Environment) and view reappears.
struct Person: Identifiable {
let id = UUID()
let name: String
}
struct ContentView: View {
@State var people: [Person] = [.init(name: "mike")]
@State var isPresented = false
var body: some View {
NavigationStack {
List(people) { person in
Text(person.name)
}
.navigationTitle("People")
.navigationDestination(isPresented: $isPresented) {
NewPerson(people: $people)
}
.toolbar {
ToolbarItem {
Button("Add") {
isPresented.toggle()
}
}
}
}
}
}
struct NewPerson: View {
@Environment(\.dismiss) var dismiss
@Binding var people: [Person]
var body: some View {
Button("Add and Back") {
people.append(.init(name: "ace"))
dismiss()
}
}
}
let words = ["@apple", "#swift"]
let regex = Regex {
ChoiceOf {
ForEach(words, id: \.self) { word in
OneOrMore(word)
}
}
}
I run into Thread 1: EXC_BREAKPOINT Error, This code should be right.
import Foundation
import RegexBuilder
let string = "https://swift.org, #swift, @swift"
let regex = Regex {
ChoiceOf {
OneOrMore(.url())
WordWithPrefix(prefix: "@")
WordWithPrefix(prefix: "#")
}
}
struct WordWithPrefix: RegexComponent {
let prefix: String
@RegexComponentBuilder
var regex: Regex<some RegexComponent> {
prefix
OneOrMore(.word)
}
}
for match in string.matches(of: regex) { // Thread 1: EXC_BREAKPOINT (code=1, subcode=0x22a78b848)
print(String(string[match.range]))
}
SwiftUI's @State reuses same data?
(ContentView) switch user then,
(SubView) SubView should reset dates([Date]), But dates has previous data.
struct ContentView: View {
let users: [String]
@State var selectedUser: String
init() {
self.users = ["User1", "User2", "User3"]
self.selectedUser = users.first!
}
var body: some View {
VStack {
Text(selectedUser)
Picker("User", selection: $selectedUser) {
ForEach(users, id: \.self) { user in
Text(user)
.tag(user)
}
}
.pickerStyle(.segmented)
SubView(user: selectedUser)
}
}
}
struct SubView: View {
let user: String
@State var dates: [Date] = []
var body: some View {
List {
Section(user) {
Button("Add") {
dates.append(.now)
}
ForEach(dates, id: \.self) { date in
Text(date, format: .iso8601)
}
}
}
}
}
I want to remove Cookies(Login) of SFSafariViewController.
disabled does not wok in List selection
struct ListDisableTest: View {
let disableIDs: [Int] = [1, 3]
@State var selection: Set<Int> = []
var body: some View {
List(1..<20, id: \.self, selection: $selection) { i in
Text("\(i)")
.tag(i)
.disabled(disableIDs.contains(i))
}
.environment(\.editMode, .constant(.active))
}
}
@Environment can't use for Binding?
@Observable
final class View1Model {
var text: String = ""
}
struct View1: View {
@State var viewModel = View1Model()
var body: some View {
View2()
.environment(viewModel)
}
}
struct View2: View {
@Environment(View1Model.self) var viewModel
var body: some View {
TextField("Text", text: $viewModel.text) // Cannot find '$viewModel' in scope
}
}
Why AppIntentConfiguration is covered with gray(redacted)?
I used just Widgets Template(AppIntentConfiguration)
Widget is covered with gray(redacted).