Post

Replies

Boosts

Views

Activity

Reply to How to set up a expandable TableView Cell?
Please, when you paste code, use Paste and Match Style to avoid extra lines: let heightOfBottomView = CGFloat(60) let basicHeight = CGFloat(50) lazy var fullHeight = heightOfBottomView + basicHeight var visibleBottomViews : [Bool] = [] func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) - CGFloat { if indexPath.row == 0 { //SegmentControl Rent of Buy return 60 } if indexPath.row == 1 { //Segment Control Property Types return 60 } if indexPath.row == 2 { //Price Slider return visibleBottomViews[indexPath.row] ? fullHeight : basicHeight } if indexPath.row == 3 { //Size Slider return 118 } } Error is probably line 18. Reason is that you have not populated visibleBottomViews array. You should In ViewDidLoad: visibleBottomViews = Array(repeating: false, count: 4) // The exact count should be the table rows count Note: I assumed all rows could have variable height. If variable size is only for row 2, you could replace the array by a single Bool line 5: var visibleBottomView = false and if indexPath.row == 2 { //Price Slider return visibleBottomView ? fullHeight : basicHeight }
Topic: UI Frameworks SubTopic: UIKit Tags:
Apr ’21
Reply to Details of making an app
how an social media app like Instagram or Snapchat is actually developed? What do you mean ? Which language ? What is the purpose of your question ? If you want to do some similar app, you can develop in Swift with Xcode (I advise to use UIKit not SwiftUI). But take care, that is probably a be hard for the first app of an aspiring developer.
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’21
Reply to UserDefaults with Struct - TableView not displaying data from saved from UserDefaults?
The problem is not UserDefaults but errors in your code (formatted with tool): struct Person: Codable { var firstName: String var lastName: String } class viewController: UIViewController { var newPerson = [Person]() override func viewDidLoad() { let person = [Person(firstName: "Peterson", lastName: "Jota") , Person(firstName: "John", lastName: "Paul")] let encoder = JSONEncoder() if let encoded = try? encoder.encode(person) { UserDefaults.standard.set(encoded, forKey: "savedPerson") } } } var person = [Person]() func tableView( tableView: UITableView, numberOfRowsInSection section: Int) - Int { return person.count } func tableView( tableView: UITableView, cellForRowAt indexPath: IndexPath) - UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "cellID", for: indexPath) as! UITableViewCell cell.textLabel?.text = person[indexPath.row] return cell } Line 8, you declare newPerson but never use it. What is it for ? Line 12, you create person. But it does not exist outside of viewDidLoad. So line 25, person is empty. Hence return 0. And so, nothing is displayed in TableView. Some other comments for better readabilty Names of class should start with Uppercase : class ViewController person is an array, better name it persons. Declaration better be at beginning of class. So, more correct code: struct Person: Codable { var firstName: String var lastName: String } class ViewController: UIViewController { var newPerson = [Person]() // == Where do you use it ? var persons = [Person]() // renamed override func viewDidLoad() { // NOT Redeclare HERE let person = [Person(firstName: "Peterson", lastName: "Jota") , Person(firstName: "John", lastName: "Paul")] person = [Person(firstName: "Peterson", lastName: "Jota") , Person(firstName: "John", lastName: "Paul")] // Now, array is populated let encoder = JSONEncoder() if let encoded = try? encoder.encode(persons) { UserDefaults.standard.set(encoded, forKey: "savedPerson") } } } func tableView( tableView: UITableView, numberOfRowsInSection section: Int) - Int { return persons.count } func tableView( tableView: UITableView, cellForRowAt indexPath: IndexPath) - UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "cellID", for: indexPath) as! UITableViewCell cell.textLabel?.text = persons[indexPath.row] return cell } If that works, don't forget to close the thread. Otherwise tell exactly what the remaining problem is and post more code if needed.
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’21
Reply to SCNNode not at the center
I don't know, I would have expected them to be both 0, right? No, screen center should be close to the values you get. No, I did not. What exactly do you mean by that? that, you mean Did you try to debug the view hierarchy ? When you run code in simulator, if you breakpoint, then you will see on the line at top of console panel a series of icons. The seventh from the left is the debug hierarchy (icon is like this 🀓) When you click, you will see the realtime view displayed and you can rotate the view to see all objects. Try to see if some are off bounds. Maybe this could help you (even though it is more ARKit, but that may help you understand what's occurring): https://stackoverflow.com/questions/55906182/how-to-position-scenenode-always-at-the-center-of-the-sceneview-while-using-arfa
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’21
Reply to Cannot find 'segmentedControl' in scope?
Looks like you have not defined segmentedControl anywhere. In fact, you have to use sender (which is in fact the segmentedControl). Just change as: @IBAction func genderButton(_ sender: UISegmentedControl) { switch sender.selectedSegmentIndex { case 0: userGender = "Female" case 1: userGender = "Male" default: return } } If that's OK, please don't forget to close the thread by marking the correct answer (it seems you have several other threads that you didn't close ; please do it as well)
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’21
Reply to Learning Swift my comparing Objective-C
If you search Comparison between Swift and objC, you will find a lot of material. Just for illustration: https:// www.educba. com/ swift-vs-objective-c/ Some of the major difference between Swift vs Objective C: ••• Swift is the latest programming language that is developed by Apple and can be run on various cross-platform operating systems such as Linux, Darwin, Free BSD, etc., whereas Objective C is a general-purpose, object-oriented programming language used by Apple in its operating systems and APIs Cocoa, etc. ••• Swift has several programming features such as safe programming patterns, syntax like Objective C, complete access to Cocoa frameworks, whereas Objective C also supports the same features as C++ except for STL and includes foundational frameworks. ••• Swift has object-oriented and procedural features in its language and in-built functionalities in its library, whereas Objective C has different data types, tokens to recognize the identifiers, declarations and assignments and pre-processor to define constants. ••• Swift supports different operators such as Arithmetic Operators, Logical Operators, Bitwise Operators, Relational Operators, Assignment Operators, Range Operators, and Miscellaneous Operators, whereas Objective C also supports the same operators except for range and pre-processors which are not part of the compilation process. ••• Swift supports Dictionaries, Functions, Closures, Enumerations, Structures, etc., whereas Objective C supports Posing, Extensions, Dynamic Binding, Protocols, Composite Objects, Memory Management, and Enumerations. ••• Swift supports optional chaining, typecasting, generics, protocols, subscripts, etc., whereas Objective C allows dynamic dispatch, auto-generation of accessors to access member variables and properties and allows a method and a name to share the same identifier. ••• In Swift, calling a method will be decided at compile time and is similar to object-oriented programming, whereas in Objective C, calling a method will be decided at runtime, and also Objective C has special features like adding or replacing methods like on a class which already exists. ••• In Swift, errors can be handled using protocols to avoid the unexpected flow of program control, whereas Objective C has nil which can be safely handled in a powerful way by safely sending messages to nil objects. ••• In Swift, operator overloading is supported and is global in terms of scope and simple, whereas Objective C does not support default parameters but can be implemented by multiple methods manipulation and also do not support private members. ••• In Swift, Arc (Automatic Reference Counting) is the feature that handles the garbage collection where emptied memory is allocated to the required processes. In contrast, Objective C does not support stack-based memory objects and allocating memory in Objective C is very expensive. It plays a key role in writing successful programs for the delivery of efficient applications. ••• In Swift, class objects are declared normally. They are similar to that of general object-oriented programming languages. In contrast, Objective C has a composite object feature with an embedded object inside an object, which means a private cluster object will be embedded into the main object and some primitive methods. ••• In Swift, advanced operators exist to handle the manipulation of the complex value, whereas Objective C has a fast enumeration feature where collections are core components of this feature. There are also translators from objC to Swift (each on web), but they do not handle all languages features. Just for basic conversion. Why do you need this comparison ? Maybe you are an objC expert ? Anyway, it may not the best idea to try to learn by comparison. I feel it is better to learn Swift per se, and then find out, when needed how to port something to wifi if you convert some code.
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’21
Reply to insert Json file into core Data
Now I do not know what to do next.  next… do you mean insert in CoreData ? If so, you will find a lot of useful information here https://stackoverflow.com/questions/51869261/save-json-to-coredata-as-string-and-use-the-string-to-create-array-of-objects/51873317
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’21
Reply to insert Json file into core Data
I would first convert the list into an array. let recettes = "{[{\"title\" : \"Mini pork pies with piccalilli\", \"category\" : \"meat\"}, {\"title\" : \"apple crumble\", \"category\" : \"dessert\"}]}" define a Decodable class . ``` class Receipt: Decodable { } Have a look here https://stackoverflow.com/questions/30480672/how-to-convert-a-json-string-to-a-dictionary
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’21