I have a project, after update it to swiftUI 3.0, it is throw an error for
.animation(.spring())
as animation' was deprecated in iOS 15.0: Use withAnimation or animation(_:value:) instead, any idea?
@Binding var display: Bool
private var background: some View {
Color.black
.fillParent()
.opacity(0.6)
.animation(.spring())
}
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I have a problem when try to pass data from one view to another view, it is throw an error for
ImageDetails()
as a "Missing argument for parameter 'data' in call"
I do not know what I missed?
struct ImageModel: Identifiable, Hashable {
var id = UUID().uuidString
var name: String
}
var datas = [
ImageModel(name: "davis"),
]
struct ImageRowView: View {
var data: ImageModel
var body: some View {
NavigationLink(destination: ImageDetailsView(data: ImageModel)){
HStack{}
}}}
struct ImageDetailsView: View {
var body: some View {
ImageDetails()
}
}
struct ImageDetailsView_Previews: PreviewProvider {
static var previews: some View {
ImageDetailsView()
}
}
struct ImageDetails : View {
var data: ImageModel
var body: some View{
VStack{
Text(data.name)
}
}
I have simple app, when I run my project it work, but then throw error after running like "Thread 1: Fatal error: No ObservableObject of type msgDatas found. A View.environmentObject(_:) for msgDatas may be missing as an ancestor of this view."
struct Home: View {
@EnvironmentObject var data : msgDatas
var body : some View{
ZStack{
Color("bg").edgesIgnoringSafeArea(.top)
NavigationLink(destination: Message(), isActive: $data.show) {
Text("")
}
VStack{
topView()
}
}
}
}
I have a simple SwiftUI project, when I click the any list items, I want to route different SwiftUI. Below, I used arrays, and for every SwiftUI, I want to use [0], [1],..., but it throw error, I do not know why? Any idea?
ContentView:
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationView {
List(contacts) { contact in
NavigationLink(destination: NumberOneView(contact: contact)) {
ContactRow(contact: contact)
}
}
.navigationBarTitle("Contacts")
}
.environment(\.colorScheme, .light)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
struct ContactRow: View {
let contact: Settings
var body: some View {
HStack {
Image(contact.imageName)
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 20, height: 20)
VStack(alignment: .leading) {
Text(contact.name)
.font(.system(size: 21, weight: .medium, design: .default))
}
}
}
}
Settings.swift:
import Foundation
import SwiftUI
struct Settings: Identifiable {
let imageName: String
let name: String
let id = UUID()
}
let contacts = [
Settings(imageName: "image1", name: "NumberOne"),
Settings(imageName: "image2", name: "NumberTwo"),
Settings(imageName: "image3", name: "NumberThree"),
Settings(imageName: "image4", name: "NumberFour"),
]
NumberOneView:
import SwiftUI
struct NumberOneView: View {
let contact: Settings
var body: some View {
Text("hey")
}
}
struct NumberOneView_Previews: PreviewProvider {
static var previews: some View {
NumberOneView(contact: contacts[0])
}
}
NumberTwoView:
import SwiftUI
struct NumberTwoView: View {
let contact: Settings
var body: some View {
Text("hey")
}
}
struct NumberTwoView_Previews: PreviewProvider {
static var previews: some View {
NumberTwoView(contact: contacts[1])
}
}
I ask this question before, it was answered but it is not work for many data, like when I click the any list items, all details pass name of "david", I want to pass data of user which I clicked, where I missed here?
struct ImageModel: Identifiable, Hashable {
var id = UUID().uuidString
var name: String
}
var datas = [
ImageModel(name: "davis"),
ImageModel(name: "carry"),
ImageModel(name: "maria"),
]
struct ImageRowView: View {
var data: ImageModel
var body: some View {
NavigationLink(destination: ImageDetailsView(data: ImageModel)){
HStack{}
}}}
struct ImageDetailsView: View {
var body: some View {
ImageDetails(data: ImageModel(name: "davis"))
}
}
struct ImageDetailsView_Previews: PreviewProvider {
static var previews: some View {
ImageDetailsView()
}
}
struct ImageDetails : View {
var data: ImageModel
var body: some View{
VStack{
Text(data.name)
}
}
I have multiple alert dialog in project, just one of them is work, but I am still do not know why I am not use second one, so how we can use multiple .alert dialog in SwiftUI?
struct MyView: View {
@State private var selectedUsers: MyModel?
@State var datas: [MyModel]
@State private var deleteRow = false
@State private var deleteRows = false
var body: some View {
ScrollView(.vertical, showsIndicators: false, content:
{
VStack(content: {
ForEach(datas){ data in
MyRowView(data: data)
.contextMenu {
Button(action: {
deleteRow = true
}) {
Text("delete")
}
Button(action: {
deleteRows = true
}) {
Text("delete")
}
}
.onTapGesture {
selectedUsers = data
}
.alert(isPresented: $deleteRow) {
Alert(title: Text("title"),
message: Text("message"),
primaryButton: .destructive(Text("Delete")) {
self.delete(item: data)
},
secondaryButton: .cancel())
}
.alert(isPresented: $deleteRows) {
Alert(title: Text("title"),
message: Text("message"),
primaryButton: .destructive(Text("Delete")) {
self.datas.removeAll()
},
secondaryButton: .cancel())
}
} .onDelete { (indexSet) in
self.datas.remove(atOffsets: indexSet)
}})
})}
private func delete(item data: MyModel) {
if let index = datas.firstIndex(where: { $0.id == data.id }) {
datas.remove(at: index)
}
}}
I have simple app in SwiftUI, when I use @Binding var show : Bool for second register screen,
it is throw an error for this line of code
init(state: AppState) {
self.viewModel = RegisterViewModel(authAPI: AuthService(), state: state)
}
as a "Return from initializer without initializing all stored properties" any idea?
first screen:
import SwiftUI
struct RegisterFirstScreen: View {
@Binding var show : Bool
init(state: AppState) {
self.viewModel = RegisterViewModel(authAPI: AuthService(), state: state)
}
var body: some View {
NavigationLink(destination: RegisterSecondScreen(state: viewModel.state, show: $show),
isActive: self.$pushActive) {
Button {
viewModel.signUp()
} label: {
Text("Register Now")
.padding()
}
}
}
second screen:
struct RegisterSecondScreen: View {
@ObservedObject var state: AppState
@Binding var show : Bool
var body: some View {
Text("Next main screen")
}}
I have simple project in swiftUI, everythings is work, but
HStack for Rectangle() as I mention below, do not alignment the Rectangle and text at the same line, and idea will be appreciated.
struct App: View {
var body: some View {
GeometryReader{g in
ZStack {
ForEach(0..data.count) { i in
DrawShape(center: CGPoint(x:g.frame(in: .global).width/2, y: g.frame(in: .global).height/2), index: i)
}
}
}
.frame(height: 200)
.clipShape(Circle())
.shadow(radius: 10)
VStack{
ForEach(data) { i in
HStack {
Text(i.name)
.frame(width:100)
.padding()
GeometryReader { g in
HStack{
Spacer(minLength: 0)
Rectangle()
.fill(i.color)
.frame(width: self.getWidth(width: g.frame(in: .global).width, value: i.percent) ,height: 10)
Text(String(format: "\(i.percent)", "%.0f"))
.fontWeight(.bold)
.padding(.leading,10)
.frame(width:80)
Spacer()
}.frame(width: 240, height: 30)
}
}
}
.padding()
Spacer()
}
}
func getWidth(width: CGFloat, value: CGFloat) - CGFloat {
let temp = value / 100
return temp * width
}
}
I want to use NavigationLink for open the chat detail view when I click the rows items. Here example of code I mentioned. Any idea will be appreciated.
RecentRowView:
import SwiftUI
struct RecentRowView: View {
var recent: Profile
var animation: Namespace.ID
// Environment Object...
@EnvironmentObject var profileData: ProfileDetailModel
var body: some View {
HStack(spacing: 15){
// Making it as clickable Button....
Button(action: {
withAnimation{
profileData.selectedProfile = recent
profileData.showProfile.toggle()
}
}, label: {
ZStack{
// Without matched geometry effect simply showing image...
Image(recent.profile)
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 60, height: 60)
.clipShape(Circle())
if !profileData.showProfile{
Image(recent.profile)
.resizable()
.aspectRatio(contentMode: .fill)
// Matched Geometry Effect...
// Giving unique ID that is from UUID from profile Model....
.matchedGeometryEffect(id: recent.id, in: animation)
.frame(width: 60, height: 60)
.clipShape(Circle())
}
}
})
// it decreased the highlight color....
.buttonStyle(PlainButtonStyle())
VStack{
NavigationLink(destination: ChatDetailView(), isActive: $profileData.show) {
HStack{
VStack(alignment: .leading, spacing: 8, content: {
Text(recent.userName)
.fontWeight(.bold)
Text(recent.lastMsg)
.font(.caption)
.foregroundColor(.gray)
})
Spacer(minLength: 10)
Text(recent.time)
.font(.caption2)
.foregroundColor(.gray)
}
Divider()
}
}
}
.padding(.horizontal)
}
}
struct RecentRowView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
ContentView:
struct ContentView: View {
// ANimation Namespace...
@Namespace var animation
// StateObject...
@StateObject var profileData = ProfileDetailModel()
var body: some View {
Home(animation: animation)
// setting Environment Object...
.environmentObject(profileData)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
NavigationView{
ContentView()
}
}
}
ChatDetailView:
import SwiftUI
struct ChatDetailView: View {
var body: some View {
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
}
}
struct ChatDetailView_Previews: PreviewProvider {
static var previews: some View {
ChatDetailView()
}
}
When I pod install in terminal it say "[!] Error installing MaterialControls", Cloning into '/var/folders/w_/46rzmwwn0k73x1dtmmqk4m_r0000gn/T/d20210618-4079-1b04w72'...
remote: Repository not found.
fatal: repository 'https://github.com/fpt-software/Material-Controls-For-iOS.git/' not found. Any idea?
I want to use segue programmaticly , but it throw error for
ForgotPasswordEmailCheckController as "Cannot convert value of type 'ForgotPasswordEmailCheckController.Type' to expected argument type 'UIViewController'" Any idea?
ForgotPasswordEmailCheckController:
class ForgotPasswordEmailCheckController: UIViewController, UITextFieldDelegate {
var storyboardId: String {
return (value(forKey: "ForgotPasswordEmailCheck") as? String)!
}
LoginViewController:
@IBAction func forgotPassword(_ sender: Any) {
let mainStoryboard = UIStoryboard(name: "Main", bundle: Bundle.main)
guard let forgotPasswordEmailCheck = mainStoryboard.instantiateViewController(identifier: "ForgotPasswordEmailCheck") as?
ForgotPasswordEmailCheckController else {
print("Not correct password")
return
}
navigationController?.pushViewController(ForgotPasswordEmailCheckController, animated: true)
}
I have list image and when I click the image list items it show me image details, but it show same image even I click the different image? any idea?
Datas:
struct Datas: Identifiable {
var id = UUID().uuidString
var name: String
var detail: String
var image: String
}
var datas = [
Datas(name: "People1.jpg"),
Datas(name: "People.2jpg"),
Datas(name: "People3.jpg"),
]
RowView:
struct RowView: View {
var docs: Datas
var body: some View {
NavigationLink(destination: ListDetailsView(docs: datas[0])) {
Image(docs.image)
.resizable()
.frame(width: 64, height: 48)
}
}
ListDetailsView:
struct ListDetailsView: View {
var docs: Datas
var body: some View {
ZStack{
Image(docs.image)
}
}
}
struct ListDetailsView_Previews: PreviewProvider {
static var previews: some View {
ListDetailsView(docs: datas[0])
}
}
I have project in SwiftUI 2.0 and I want to update it for Swift 3.0, is it possible to do that?
I have IOS projets, it work but suddenly crash and throw error like "Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value" Why?
import Foundation
import AVFoundation
struct Video : Identifiable {
var id = UUID()
var player : AVPlayer
var user: User
}
struct User: Identifiable {
var id = UUID()
let userName: String
let userImage: String
}
struct MockData {
let videos: [Video] = [
Video(player: AVPlayer(url: URL(fileURLWithPath: Bundle.main.path(forResource: "reel_1", ofType: "mp4")!)),
user: User(userName: "cristiano", userImage: "user_9")),
Video(player: AVPlayer(url: URL(fileURLWithPath: Bundle.main.path(forResource: "reel_2", ofType: "mp4")!)),
user: User(userName: "mann_daar", userImage: "user_3")),
]
}
I want to put BookListView() on the content view but it throw error like "Cannot convert value of type 'AnyViewModel<BookListState, Never>.Type' to expected argument type 'AnyViewModel<BookListState, Never>'" Any idea?
BookListView:
import SwiftUI
struct BookListState {
var service: BookService
var books: [Book]
}
struct BookListView: View {
@ObservedObject var viewModel: AnyViewModel<BookListState, Never>
var body: some View {
NavigationView {
ScrollView {
VStack(alignment: .leading){
ForEach(viewModel.state.books) { book in
NavigationLink(destination: NavigationLazyView(BookDetailView(service: self.viewModel.state.service, bookId: book.id))) {
BookRow(book: book)
}
}
}
}
}
}
}
struct BookListView_Previews: PreviewProvider {
static var previews: some View {
let viewModel = AnyViewModel(BookListViewModel(service: MockBookService()))
return BookListView(viewModel: viewModel)
}
}
ContentView:
import SwiftUI
struct ContentView: View {
var body: some View {
BookListView(viewModel: viewModel)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}