Posts

Showing posts with the label swift

Parse JSON in Swift 24hours of problems

Parse JSON in Swift 24hours of problems I am really struggling to parse a json file into my iOS app in Swift. I have a JSOn output from an SQL db. I think the formatting is wrong and the data headers are a bit ambiguous but my developer who I hired to create the process is happy with the output. Link below. So in the last 3 days I have read all of the Apple Developer materials on parsing JSON, also watched numerous tutorials which all cover pretty much the same data, and I don't know how much I have read and converted into actual projects which have all failed. I am really needing some guidance here. I have even in a desperate attempt to understand my problem from a different perspective I have looked at how it is done in other languages. This is the latest iteration: func flightData()-> [[String: String]]{ let url = URL(string: "http://35.237.114.234/api/index.php?uid=Bx7faf08A9fYJ7bZCNMUX9EzxYN2") guard let jsonFileURL = Bundle.main.url(forResource: "jso...

UISearchBar increases navigation bar height in iOS 11

Image
UISearchBar increases navigation bar height in iOS 11 I have my UISearchBar being part of the navigation bar like: UISearchBar let searchBar = UISearchBar() //some more configuration to the search bar ..... navigationItem.titleView = searchBar After updating to iOS 11 something weird happened to the search bar in my app. On iOS 10 and prior I had my navigation bar looking like: iOS 11 iOS 10 Now with iOS 11 I have: iOS 11 As you can see there is difference in the rounding of the two search bars which does not bothers me. The problem is that the search bar increases the height of the navigation bar. So when I go to another controller it looks weird too: In fact that weird black line's height plus the current navigation bar's height is equal to the height of navigation bar shown in the second picture ... Any ideas how to get rid of the black line and having consistent navigation bar height across all view controllers ? Possible duplicate of iOS...

Need Help populating array with JSON data using SwiftyJSON

Need Help populating array with JSON data using SwiftyJSON I want to populate an array I have with JSON data. I'm using SwiftyJSON and Alamofire. I'm new to parsing JSON, so i apologize for any ignorance on my end. The URL below is the url i'm inserting in getAllTimeAverage(). Any help would be awesome!! thanks! This is the JSON Data https://apiv2.bitcoinaverage.com/indices/global/history/BTCILS?period=alltime&format=json This is the array i want to populate var allTimeAverages: [Any] = These are my functions. I call them in my cellForRowAt:, when i print the allTimeAverages.count, I get back zero. func getAllTimeAverage(url: String) { Alamofire.request(url, method: .get) .responseJSON { response in if response.result.isSuccess { print("Sucess! Got the Bitcoin Data") let bitcointJSON : JSON = [JSON(response.result.value!)] self.updateAverageAllTime(json: bitcointJSON) } else {...

Swift iOS -How to Switch / Toggle between two UIWindows and make either the keyWindow

Image
Swift iOS -How to Switch / Toggle between two UIWindows and make either the keyWindow I created an additional UIWindow that will get presented on top of the main window. The user presses a button and it transitions over the main window. The user can minimize the additional window and it will sit above the tabBar like it the picture below. They can enlarge it to cover the main window or dismiss it and it gets destroyed. It works fine. I also created a custom action sheet that launches from the bottom of the screen. If the additional window completely covers the main window and the action sheet is launched, it will launch perfectly inside the additional window. If the additional window isn't on the screen it launches perfectly inside the main window. The problem is if the additional window is minimized on screen and I want to launch the action sheet from the main window, the action sheet launches inside the additional window instead, it cannot distinguish between the two. I opened ...

Initial ViewController still showing after segue

Image
Initial ViewController still showing after segue The app I am currently working on requires that I do not use ANY storyboards. Therefore I need to do everything programmatically. One thing I seem to be struggling with is switching between two UIViewControllers. The code I am using to go from VC1 to VC2 is: self.present(signUpVC(), animated: true, completion: nil) And the code I am using to go from VC2 back to VC1 is: self.dismiss() The problem I seem to be facing is that as VC2 is coming up, VC1 is still visible in the background (frame 1): Here is the next frame: This is the final frame of the transition, and as you can see, the initial view is still visible in the background (Frame 3): Is there any way I can fix this issue? Is the background of the view controller clear? Show some code – Scriptable Jun 29 at 22:20 ...

Operation not permitted when executing 'killall' with Swift

Image
Operation not permitted when executing 'killall' with Swift I'm trying to create a menu bar app to hide desktop icons and hopefully various other things mostly to learn more about Swift, and for some reason I can't get it to work. When I run this program and click on one of the menu items, nothing happens and I get this warning in the console: killall: warning: kill -TERM 15175: Operation not permitted Other commands work, but any variant I try on "killall" spits out something like the above. Currently my code looks like this: @discardableResult func killStuff(_ args: String...) -> Int32 { let task = Process() let pipe = Pipe() task.launchPath = "/usr/bin/killall" task.arguments = args task.standardOutput = pipe task.standardError = pipe task.launch() task.waitUntilExit() let data = pipe.fileHandleForReading.readDataToEndOfFile() if let output = String(data: data, encoding: .utf8) { print(output) ...

Firestore & Swift

Firestore & Swift Currently I'm working on a project which uses Firestore. The problem I am facing is as follows: I want to fill a collectionview with data from Firestore, the data is an image + a label. Once a user clicks on the item (image + label) in the collectionview they go to that categorie. So once they click they will get a new collectionview with the items of that categorie (also just an image + label). Now my question is how do I do this? Cause I can't seem to find related study material for my problem. I have been looking all over Google, YouTube and what not. Most of the tutorials or guides I find are for Firebase Realtime Database (so not Firestore) or are just flat out outdated (pre 2017). Also I wonder what the best practices are, do I make a struct for my categories and items? Looking for all round tips here or good reading material so I can learn how to do this. Thanks in advance. This is way too broad a topic for an answer, an...

Make the last row in UITableView appear at top

Make the last row in UITableView appear at top I have a UITableView with a random number of custom cells. It's working fine. I am moving the selected cell to the top of the UITableView with: tableView.scrollTo(index path animated) However, when the selected cell is on the last full 'page' of cells, this doesn't work - obviously. Can I make this work by somehow 'padding' out the table with empty space, dependent on the Y position of the selected cell, so that even selecting the last row, it would animate and move to the top of the table view? I thought: let point = CGPoint(x: 0, y: 200) tableView.setContentOffset(point, animated: false) would work, but it didn't (the 200) was a test amount. I'm sure this is possible, could I please get a pointer? 2 Answers 2 If you want to allow a table view to be scrolled far enough for the last row to reach the top of the screen, set...

SWIFT model for parsing JSON

SWIFT model for parsing JSON I need to parse the data of JSON. For this I will use the protocol Codable . The json received looks like this (this is the part that interests me): ( { description = mySecondGist; files = { "gistfile1.txt" = { filename = "gistfile1.txt"; language = Text; "raw_url" = "https://gist.githubusercontent.com/VladimirKhuraskin/9ca2362c09cebcc16bd74f51f267231a/raw/74caacd3ad3eedb369a07b926327d2ef37e3eefc/gistfile1.txt"; size = 17; type = "text/plain"; }; }; } ) I made this model: struct Gists: Codable { var description: String? var files: DetailGist? private enum CodingKeys: String, CodingKey { case description case files } } struct DetailGist: Codable { var filename: String? var rawUrl: String? private enum FileCodingK...

Circular image is square on first table refresh

Image
Circular image is square on first table refresh I have a search bar connected to my UITableView . UITableView Here is my code so far: func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = SongPicker.dequeueReusableCell(withIdentifier: "cell")! // Image cell.imageView?.image = songHandler.songItems[indexPath.row].songImage?.cropToBounds() cell.imageView?.layer.cornerRadius = cell.imageView!.frame.width / 2 cell.imageView?.layer.masksToBounds = true cell.imageView?.layer.borderWidth = 3 cell.imageView?.layer.borderColor = UIColor.lightGray.cgColor // Song name cell.textLabel?.text = songHandler.songItems[indexPath.row].songName // Artist name cell.detailTextLabel?.text = songHandler.songItems[indexPath.row].songArtist return cell } ( SongPicker is my table) SongPicker By printing out the result of cell.imageView?.layer , I can see that when the images first load, they do no...

UITableView doesn't show content of the custom cell?

UITableView doesn't show content of the custom cell? I'm beginner in iOS, so bear with me. I have several problems. First: When app is launched, search bar should be hidden, and when user swipes down the search bar should appear like this: when the app is launched Second: When user taps on search bar, the table view should show cells like this: when user taps search bar but for some reason table view won't show the content of said cell, it shows the name of the store in search bar: shows only name of the store(I connected delegate and dataSource). This is my code: import UIKit import Foundation class LOSocialWallPublicViewController: UIViewController, UISearchBarDelegate { //MARK: Variables let screenWidth = UIScreen.main.bounds.width let screenHeight = UIScreen.main.bounds.height var searchController = UISearchController() var suggestionsTableView: UITableView? var hidesSearchBarWhenScrolling = true var storeTableView: UITableView? var dat...