Post

Replies

Boosts

Views

Activity

Reply to support need for old swift Vs new swift
I'm trying to follow STORMVIEWS tutorial which was made with an old version of swift were viewed load was still available The viewDidLoad method is still available. Your problem is that you are using SwiftUI to follow a tutorial that uses UIKit. Start over by creating a UIKit project. Take the following steps to create a UIKit project in Xcode: In Xcode choose File > New > Project. Select iOS from the platforms at the top of the New Project Assistant. Select the App template from the list of iOS app templates. Click the Next button. Choose Storyboard from the Interface menu. Read the following article for more details and a screenshot: https://www.swiftdevjournal.com/xcode-11-missing-view-controllers/
Topic: Programming Languages SubTopic: Swift Tags:
Feb ’24
Reply to Could not locate device support files
If the solutions in the following article don't work: https://www.swiftdevjournal.com/dealing-with-failed-to-prepare-device-for-development-error-message-in-xcode/ You won't be able to run and debug the project on your iPhone running iOS 17.3. You have the following options: Buy a new Mac. Use Open Core Legacy Patcher to update your current Mac to the latest version of macOS so you can use Xcode 15. Use an iOS device running iOS 16 or earlier to run your project.
Feb ’24
Reply to Xcode Showing Build Failed
The most likely cause of your problem is you are trying to place and run multiple small programs in one Xcode project. Each program has its own main function, but a C program can have only one main function. If you add three files to your project, intending each file to be its own program, and try to run the project, Xcode doesn't know you want to run only one of the files. It assumes you want to run all the files, sees you have three main functions, and generates a link error. Xcode is designed to have one program per project, no matter how small the program is. If you are learning C and writing multiple small programs, you have the following options: Create one Xcode project for each program. Create one Xcode project and add a target for each program. Use the jump bar in the Xcode toolbar above the code editor to choose the target to run. Create one Xcode project and use the target membership checkboxes on the right side of the project window to tell Xcode which files/programs you want to build and run. Use a text editor like VS Code, TextMate, or BBEdit to write your code instead of Xcode. I know TextMate comes with a bundle to run your programs from inside the editor. VS Code probably has an extension that allows this as well.
Feb ’24
Reply to support need for old swift Vs new swift
Your first example uses SwiftUI. Every SwiftUI view requires a body. var body: some View { // Code inside the body removed. } The body property must return a SwiftUI view. The code in your body property does not have a SwiftUI view in it so you are going to get an error when you build the project. You should move all the code you have in body into a separate function. I also recommend going through a book or course to learn SwiftUI. The site Hacking with Swift has a free 100 day course that teaches SwiftUI. https://www.hackingwithswift.com/100/swiftui
Topic: Programming Languages SubTopic: Swift Tags:
Feb ’24
Reply to Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value
The most likely cause of the error is that the outlets are not connected in the storyboard. Use the connections inspector for the storyboard to check the connections. Open your storyboard in Xcode and choose View > Inspectors > Connections to open the connections inspector. You may find the following article helpful: https://www.swiftdevjournal.com/fixing-the-thread-1-fatal-error-unexpectedly-found-nil-while-implicitly-unwrapping-an-optional-value-error/
Topic: UI Frameworks SubTopic: UIKit Tags:
Jan ’24
Reply to How to add an object to the screen via the add button
I can help you with adding a product to the cart from the sheet. The CartManager has the function to add a product to the cart. To add a product in your sheet, add a property for the cart manager to ProductDetailSheet. Because CartManager is a class, you should use the @ObservedObject property wrapper for the cart manager. @ObservedObject var cart: CartManager You have not shown the code for the view that opens the sheet. But in that sheet you must add a property with the @StateObject property wrapper for the cart manager. @StateObject var cart: CartManager Pass the cart to the sheet. When someone taps the Add button, call the addToCart function to add the product to the cart. Button("Add") { cart.addToCart(product: product) isSheetPresented = nil } I am not sure if this is enough to get the product adding working, but it should give you a start.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’24
Reply to error during division please help me
You are dividing two integers. When the computer divides two integers, it removes the remainder. That is why you get 12.0 when you divide 25 by 2 instead of 12.5. Convert the integers to Double before doing the division to get the correct value when dividing. See the following Stack Overflow question to learn how to convert an integer to a Double: https://stackoverflow.com/questions/27467888/convert-int-to-double-in-swift I don't see any code in your calculate function where you do any calculations so I can't tell you where to put the code to convert to Double. Where do you perform the division?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’24
Reply to Why am I getting this error all over the project? Can anyone help solve it?
You have a link error, but your screenshot does not show the actual error. To find the actual error, press Cmd-9 in Xcode to open the report navigator. The report navigator will let you see all the build steps in your project. You may find the following article helpful: https://www.swiftdevjournal.com/why-wont-my-xcode-project-build/ When you find the actual error, reply in this thread and paste the text of the error message. Without the error message no one here can give you any more help. The usual causes of link errors are forgetting to include a framework and using the same name for a class or struct in your code that is in one of the frameworks your app links to.
Jan ’24
Reply to SwiftUi view responding to model changes
The reason the view doesn't respond to data changes when you switch to @State is that CheckItem is a class. The @State property wrapper works with structs, not classes. There are two ways to fix this. The first way is to make CheckItem a struct and remove @Published from any of the properties in CheckItem where you added them. By making CheckItem a struct, you can use @State and @Binding. The second way is to use @StateObject in the containing view and @ObservedObject in any other views where you want to use the CheckItem object. @StateObject is the class equivalent of @State, and @ObservedObject is the class equivalent of @Binding.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’24
Reply to Beginner error
You have two statements on one line without a semicolon separating them. You can't do that in Swift. var highscore = 0 highscore = 99 Place the statements on separate lines. var highscore = 0 highscore = 99 You could also simplify things by setting the value to 99 at the start. var highscore = 99 I don't know if that's enough to fix the build error. You didn't show much code. I recommend Hacking with Swift's 100 Days of SwiftUI free course to learn iOS development. They also have a forum where you can ask questions if you run into problems when going through the course. Their forum is more beginner friendly than this forum. https://www.hackingwithswift.com/100/swiftui
Topic: App & System Services SubTopic: Core OS Tags:
Jan ’24
Reply to XCode swift assistant editor
Im doing exactly what you said You did the first part of what I said, opening the assistant editor. That didn't work, as you get the header file for Apple's UIViewController class instead of the source code for your view controller. You didn't do the second part of what I said, opening a new editor view. Open a new editor view by clicking the rightmost button in the upper right corner of your screenshot, the button with a + sign in it. That will open a second view of the storyboard in Xcode. Above the storyboard in your screenshot is a jump bar that lets you jump to any file in your project. If you click the leftmost item in the jump bar, you will open a menu that will let you navigate through the files in your project. Go through the menus until you find your view controller file and choose that file, and you will be able to see the storyboard and source code side by side.
Jan ’24