[Solved] How to return struct in swift?
To return null object return State() To return object containing something. return State(current: StateEntry(), rStack: [], uStack: []) solved How to return struct in swift?
To return null object return State() To return object containing something. return State(current: StateEntry(), rStack: [], uStack: []) solved How to return struct in swift?
The error says you returned from init without initializing all stored properties. That’s what the problem is. You need to initialize Type and OperatingSystem in init: init () { DeviceID = 1233 Type = .Phone Operating_System = OperatingSystem(type: .iOS, version: OperatingSystemVersion(Major: 9, Minor: 0, Patch: 2)) UserID = 2 Description = “took” InventoryNR = “no17” … Read more
You cannot access and populate any view before it is loaded, and it does so only once the whole application has been loaded. A UITableView is a subclass of UIView, so the same applies in this case. “I want to do this because when tab with TableView is clicked first time -> Data loading takes … Read more
Your question is extremely vague with nothing for us to work with. But in any case, I just created an app requiring that logic so I would just share with you func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) { // Clear data if picture is repicked imageLocalURL = nil imageData = nil imageSelected = … Read more
For the future, it is better to post the relevant code here rather than post an image of all the code. You can start off with changing the cellForItemAtIndexPath implementation. You are downloading the image in the method (as a synchronous implementation). So unless the image is downloaded by contentsOfURL: and rendered, the cell won’t … Read more
Just create another UIView, add the image inside it and add it as a subview below your view. Than simply animate the frame property of the image. Not sure if this is what you need, but your question is too brief, so is my answer. solved How to make backgroundimage move in Swift iOS [closed]
If you have setup your segue in Storyboard, give the segue an identifier. (say , yourID) Then invoke the following method. self.performSegueWithIdentifier(“yourId”, sender: self) when you want to go to the next ViewController. EDIT call the method in last else. }else { self.actInd.startAnimating() var newUser = PFUser() newUser.username = username newUser.password = password newUser.email = … Read more
You are on the right track to setup the delegate. In Storyboard: create a Segue of type Embed Segue from the ContainerView to the ViewController to embed. Select the segue and set a Identifier. In Code, in prepareForSegue(): Set the myContainerView propert Set the delegate class ViewController: UITableViewController, ContainerViewDelegate { var myContainerView:ContainerView? // we do … Read more
If you want to include 0*constant: let arr = Array(0..<size).map { $0 * constant } If you don’t want to (i.e., start at 1*constant): let arr = Array(1..<size).map { $0 * constant } If you don’t want to multiply by a constant (or the constant is 1): let arr = Array(0..<size) solved pick an element … Read more
import Foundation let serverOutput = Data(“”” [ { “language”: “French”, “number”: “12” }, { “language”: “English”, “number”: “10” } ] “””.utf8) struct LangueUsers: Codable { let language: String let number: Int enum CodingKeys: CodingKey { case language case number } init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) language = try container.decode(String.self, … Read more
The error is pretty clear. numOfPrecentile is a UILabel?. You can’t compare that to a Double. I would suggest storing your calculation into a Double first before setting numOfPercentile.text. @objc func calculate() { if let yourHeightTxtField = yourHeightTxtField.text, let yourWeightTxtField = yourWeightTxtField.text { if let height = Double(yourHeightTxtField), let weight = Double(yourWeightTxtField) { view.endEditing(true) percentile.isHidden … Read more
let url = “192.168.1.1/api/project” var header = [String:String]() header[“accept”] = “aplication/json” header[“key”] = “David” let reqParam = [“project”:[“title”:”Test Title”,”description”:”Test description for new project”,”priority”:false,”category_id”:1,”location_id”:1]] Alamofire.upload(multipartFormData: { multipartFormData in for (key, value) in reqParam{ do{ let data = try JSONSerialization.data(withJSONObject: value, options: .prettyPrinted) multipartFormData.append(data, withName: key) }catch(let err){ print(err.localizedDescription) } } },usingThreshold:UInt64.init(), to: url, method: .post, headers: … Read more
// A good, more object oriented way- struct Fruit{ var name: String var cost: Double var nutrition: Int } let fruitsDataHolder = [ Fruit(name: “Apple”, cost: 10.0, nutrition: 5), Fruit(name: “Banana”, cost: 15.0, nutrition: 10) ] func getFruitsCost(fruits: [Fruit]) -> Double{ var totalCost = 0.0 for fruit in fruits{ totalCost += fruit.cost } return totalCost … Read more
This JSON is wrong. You JSON must be valid. In order to make above JSON valid we need to set array with a key. Wrong { [{ “time”: 1, “score”: 20, “status”: true, “answer”: 456 }], challenge_date”: “2019-03-13” } Correct { “array”: [{ “time”: 1, “score”: 20, “status”: true, “answer”: 456 }], “challenge_date”: “2019-03-13” } … Read more
Don’t use a label to hold information. Save the date at the moment you set your label’s text, as a Date, into your model (or simply as a property in your view controller.) Then, when you need to tell If the “label time” is before or after 4:00PM, use the Calendar method date(bySettingHour:minute:second:of:matchingPolicy:repeatedTimePolicy:direction:) to generate … Read more