Post

Replies

Boosts

Views

Activity

Reply to Cannot use instance member 'name' within property initializer; property initializers run before 'self' is available
In fact the message is pretty explicit. You try to use self (by using its name property) before self is fully initialised (use is not yet defined). That's a classical catch 22 situation in init. Unfortunately, you cannot declare use as lazy because it is an observedValue. But this should work struct OtherView: View { @State private var name: String = "" @ObservedObject var use : Use = Use(name: "") init() { use = Use(name: name) } var body: some View{ VStack{ } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Apr ’21
Reply to Uppgradera Swiftkod
I translate because I do not master swedish well enough… The code was built in 2015 on Mac IOS El Capitan. When I want to see the app on an external iPhone I get the following message "No provisioned iOS device are available with a compatible iOS version. Connect an iOS device with a recent enough version of iOS to run your application or choose an iOS simulator as the destination" . I only have an iPhone 5 and the app does not work there. Nor on any of the proposed simulators. This ***** that the app is "Succeeded" uploaded. Maybe it's a bug in the code. Can I buy your help with checking the code. I forgot how I made the code - but I need to use the app. Which iOS version on iPhone 5 ? How do you install the app on the device ? From Xcode by building the app ? Have you the full code of the app ? Is it Swift or objC code ? If you post an email for contact, I propose you to send me the full project. And I'll have a look, at least on simulators. Vilken iOS-version på iPhone 5? Hur installerar du appen på enheten? Från Xcode genom att bygga appen? Har du appens fullständiga kod? Är det Swift- eller objC-kod? Om du skickar ett e-postmeddelande för kontakt föreslår jag att du skickar mig hela projektet. Och jag tittar, åtminstone på simulatorer.
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’21
Reply to Could not dequeue a view of kind:
It would be much easier if we could get the whole code of the class… But error: reason __NSCFString * "could not dequeue a view of kind: UICollectionElementKindCell with identifier restaurantCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard" 0x00006000037a09c0 tells that : you have created a nib file for the cell (.xib): exact ? if so, you need to register the cell nib file, with code like (assuming the cell file is "restaurantCell.xib" and that restaurantCell class has the same name restaurantCell : let nib = UINib(nibName: veHeaderCell, bundle: nil) collectionView.register(nib, forCellReuseIdentifier: "restaurantCell") // I don't know who is the collectionView If the cell is defined directly in the CollectionView in Storyboard, as Custom cell, then you need to connect the cell to its class definition.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Apr ’21
Reply to unrecognized selector sent to instance 0x144b071
We do not see the error, but I understand that's the thread title… Most usual cause is that one of the IBOutlets are not connected to their object in storyboard. = Check all connections (specially yourAge) = if appears OK, do an option-clean build folder If not enough, remove the connection of yourAge (in Storyboard, right click on the textField and click the small x in the "Referenced Outlet section". And reconnect. Another possible cause depending on the error you get: @IBAction func savePersonalInfo(_ sender: Any) { userWeight = Double(yourWeight.text!) userAge = Double(yourAge.text!) } It is risky to force unwrap. yourWeight.text may be nil. And you get an optional, not a Double. And sender is a button ? It is better to have UIButton and not Any as argument. To change, you have to disconnect the IBAction first, then change Any to UIButton then reconnect IBAction. Are you sure age should be a Double, not an Int ? More robust code: @IBAction func savePersonalInfo(_ sender: UIButton) { userWeight = Double(yourWeight.text ?? "0.0") ?? 0.0 userAge = Double(yourAge.text ?? "0.0") ?? 0.0 }
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’21
Reply to migrate swift version 3 to 4
Probably because the project doesn't match the criteria for conversion. Are you sure it is not already a Swift 4 project ? Do you see some messages in the Issue Navigator (left panel), such as: Swift Conversion Group Conversion to Swift 5 is available Validate Project Settings Group xxxxxxxApp.xcodeproj Update to recommended settings If so, use those to update.
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’21
Reply to Can someone walk me through the app launch sequence at a low level?
When you learn a foreign language, do you try to learn all the details of the grammar, with all the exceptions and try to understand why it is built like this… It is an approach but not very efficient. It is usually better to start speaking and writing, then progressively dig in. IMHO that's the same for learning a new environment (XCode, Swift, APIs): learn while doing. But make sure you undertsnad what you are writing not just copying existing code. But trying to understand everything before starting would be an terrible endeavour, due to fail because one answer raises 4 outher questions which each raises 4 more… So, start learning simple app development, you will progressively learn the internal mechanisms of the OS and its frameworks. Good luck.
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’21
Reply to SwiftUI tutorial
landmarks.filter { landmark in (!showFavoritesOnly || landmark.isFavorite) } To make filter work (on the landmarks array), you need to tell it the rule for filtering. So filter has an argument which is the func to use to filter elements. In Swift, this func could be written inside the () of filter(), or outside as a closure (a func with no name). This closure has a syntax: the argument is an element of the array (filter will explore all elements) : to which you give a name, logically landmark. The func (the closure) returns true or false, which will let filter decide to keep or discard element. The body of a closure is separated from arguments (landmark) by the in keyword. after in, you have the computation of the return value. You could write this in longer forms that may help understand: landmarks.filter( { (landmark: Landmark) in return (!showFavoritesOnly || landmark.isFavorite) } ) or landmarks.filter( { landmark in return (!showFavoritesOnly || landmark.isFavorite) } ) or landmarks.filter { landmark in return (!showFavoritesOnly || landmark.isFavorite) }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Apr ’21
Reply to How to set up a expandable TableView Cell?
I did not go into the detail of the code, but I suspect constraints. Vertical constraints could force the height of the cell. Pattern is following: obj A has a constraint to the top of cell and an height constraint obj B has a vertical spacing to A and a height constraint obj C has vertical spacing to B and constraint to the bottom of cell At the end, the cell height is forced to the sum of those values.
Topic: UI Frameworks SubTopic: UIKit Tags:
Apr ’21