ios

  1. A

    Programmatically create UIView with size based on subviews(labels)

    I have a scenario where I'm needed to create an UIView completely programatically. This view is displayed as an overlay over a video feed and it contains 2 UILabels as subviews. These labels can have varying widths and heights so I don't want to create a fixed frame for the UIView or the...
  2. S

    Add CAGradientLayer to view

    I have this custom UIView import UIKit class LoginView: UIView { override init(frame: CGRect) { super.init(frame: frame) setupBackground() } required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) setupBackground() } private...
  3. S

    How to increment the value in specific node with firebase realtime database ios

    Here i'm working in a chat application, i want to maintain the unread count for the recipient side. My json structre in console looks like the scope of this question is, how to increment the value of unread_count. Prior incrementing i have the user_a_uuid and the node user_history &...
  4. V

    How to exit loop in an async call?

    Simplified version of my code is like this: var joined = false for room in rooms { checkRoom() { // async func if room.player.count == 1 { join(room) joined = true // break doesnt work here } } if joined { break; } }...
  5. L

    Vertical position is ambiguous, conflicting contraints

    I am getting the following warnings in my view controller, and I would like to understand why. Please see the image. Thank you for your help!
  6. K

    Save and resend Alamofire request

    I am using Alamofire and I want to send a get request. If this fails, I want to retry it again after some other operations. I save the request in a variable: let myRequest = Alamofire.request("myurl", method: .get) and in another function: func retry(request:DataRequest) {...
  7. R

    Variables in UICollectionViewCells change to different cells

    I have a shop menu for my game in swift. I am using a UICollectionView to hold the views for the items. There is a black glass covering over them before they are bought, and it turns clear when they buy it. I am storing data for owning the certain items in the cells' classes. When I scroll down...
  8. S

    Setup MoreViewController

    OK, I'm a sinner. The good news is: I use multiple Storyboards (yay!) The bad news: I'm not inspired enough to escape the 'More..' tab. Now: I need to make the moreviewcontroller to look like the rest of my app. So, in my I do: let tabController = UITabBarController() and in my I do...
  9. E

    Swift: Navigation Bar ist hiding although I call the required code?

    I have two VCs with the same navigation Controller and on my first VC the navigation Bar should be hidden and the second one large. The two VC are connected via a push segue. But if I click on the back button which appears after a push segue the navigation Bar appears again although when the VC...
  10. C

    Change color of text on parts of UILabel that are surrounded by asterisks

    I have a string such as the following: let myString = "This is my *awesome* label which *should* change color"; What I need to do is add this text to a UILabel, changing the text color to orange where the parts of the text are surrounded by asterisks, and removing the asterisks before...
  11. M

    Swift - Computed Property Return

    I have array of dictionaries that I will use for cells in collectionView. I'm new to swift, so I try to find the best way to store that. Now I use this code: var collectionViewData: [collectionViewStruct] = { var cell_1 = collectionViewStruct() cell_1.title = "..." cell_1.text =...
  12. T

    Search Bar displaying correct but on press wrong Contact

    I've added the Search Bar to my Contact application but after searching for the Name or the Surname is returning the correct contact. But on press is returning the wrong contact. Here is my code: override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) let store...
  13. S

    How to fetch data from post method in Swift?

    I have lists of data to be presented in tableview. The API works for POST method. But I don't get the data fetched on the tableview but it gets printed on the console. Can't we fetch data from POST method in Swift? Please help me to solve this problem. import UIKit import Alamofire class...
  14. E

    How to save objects with sub-classes using NSKeyedArchiver in Swift IOS

    I'm just trying coding in Swift and I am trying to modify this existing project in the Apple Dev Libraryre: Meals. I was hoping to put in an additional subclass such as Ingredients into the main Meal class having it as an array or ingredients. import UIKit import os.log class Meal: NSObject...
  15. M

    Load ViewController's WebView before showing

    I have an app with a ViewController that contains a WebView. Because the website the WebView is showing is quite large, I'd like to load the ViewController while the app is launching so as soon as the user opens the ViewController with the WebView it will show the already loaded page. I've tried...
  16. G

    Swift: Decodable

    Lets say i have this json from an API request: friends: { "john":31, "mark":27, "lisa":17, "tom":41 } I usually expect it in an array format: friends: [ { "john":31 }, { "mark":27 }, { "lisa":17 }, { "tom":41 } ] But the API doesn't provide me this way the results...
  17. K

    Showing onboarding Viewcontroller once

    I have an application where I am showing an onboarding screen. I now want the onboarding screen to show just once throughout the app life except the user delets and reinstall. That is the user can only see the onboarding once and when the user opens the app again, the user should be able to see...
  18. T

    Text changed event in UITextView

    I have @IBOutlet weak var messageTextView: UITextView and I want that when there is a change inside the text then print to console: blabla. I tried to add the following function, but when I change the text nothing happens: func textViewDidChange(_ textView: UITextView) { switch (textView)...
  19. U

    API Request in ReactiveSwift

    I am beginner in ReactiveSwift. I create weather app and my request does not work. func fetchCurrentWeather() -> SignalProducer<TodayWeatherData?, DownloadError> { guard let unwrappedURL = url else { return SignalProducer.empty } return URLSession.shared.reactive .data(with...
  20. S

    How to convert sequence of ASCII code into string in swift 4?

    I have an sequence of ASCII codes in string format like (7297112112121326610511411610410097121). How to convert this into text format. I tried below code : func convertAscii(asciiStr: String) { var asciiString = "" for asciiChar in asciiStr { if let number = UInt8(asciiChar...
Top