Posts

Showing posts with the label swift

Swift - Firebase how to get only childs values without parent

Swift - Firebase how to get only childs values without parent In the database i has a child cities with the name of "cities" under it and each city has multiple areas contains the coordinations I went through every child under "cities" to find the closest location and got the city name using ref.child("cities").observe() : ref.child("cities").observe() for child in snapshot.children { let childSnap = child as! DataSnapshot if let dicionary = childSnap.value as? [String: AnyObject]{ var latitude1 = dicionary["latitude"] as! Double var longitude1 = dicionary["longitude"] as! Double var altitude1 = dicionary["altitude"] as! Double lets say the closest city is "city 2" and place it in a variable called selectedCity. So I repeat and add it to ref.child("cities").child(selectedCity) : ref.child("cities").child(selectedCity) ref.child("cities").child(...

Swift charts - x axis values not aligned with bars in Group bar chart

Swift charts - x axis values not aligned with bars in Group bar chart i have created the simple bar chart with the library from https://github.com/danielgindi/ios-charts still can't figure out how to aligned x axis values with grouped bars. I am using a separate class for value formatting and i have a general function for draw n number of grouped bar charts. func createGroupedBarChart(with data: ChartDataCollection) { let grpBarChartView = BarChartView() self.addSubview(grpBarChartView) self.addConstraintsWithFormat(format: "H:|-5-[v0]-5-|", views: grpBarChartView) self.addConstraintsWithFormat(format: "V:|-5-[v0]-5-|", views: grpBarChartView) grpBarChartView.noDataText = "You need to provide data for the chart." grpBarChartView.chartDescription?.text = data.chartDescription if let barGrpChartData = data.chartData as? [BarChartGrouped] { //legend let legend = grpBarChartView.legend legend.enabled...

Very slow JSON parsing using EVReflection depending on iOS device

Very slow JSON parsing using EVReflection depending on iOS device I am obtaining a json object containing an array of objects. I am willing to parse this json using the lib EVReflection . EVReflection The operation takes a while, so I decided to monitorize the steps I'm taking, and realized the parsing of the json can take up to 20 seconds depending on the device. Using iPhone SE / iOS 11.4 it takes 4 seconds aprox. Using iPhone 5 / iOS 10.3 it takes 20 seconds aprox. I am wondering if such variation is normal just depending on devices/OS. Should I just use another lib or is there anything I can do to speed up the operation? This is the code I'm using: func getParkings(update: Bool) -> Observable<[ParkingEvo]> { if let x = parkings, !update { return Observable.just(x) } else { print("STEP 1: Calling API for parkings (NSDate())") return RxAlamofire.string(.get, PARKINGS_URL, parameters: getParameters()...

My Scrollview wont scroll ios

Image
My Scrollview wont scroll ios I have a view and inside of that view i put a scroll view. I want to make a scrollview inside of view but the problem is if i add label with multiple lines in scrollview but The result is the scrollview will stretch to right not enter to multiple lines but in storyboard the label looks fine when i run it on Simulator the label stretch to right. My goal is to make the scrollview scrollable without change the size. I already tried to centre horizontal the textfield and the label but the result i cant scroll vertical the scrollview. I already give this constraint Scroll View :- Leading, Trailing, Top and Bottom To SuperView(MainView) Label :- Leading, Trailing, Top and Bottom To SuperView(ScrollView) Leading and trailing To The Scroll View's SuperView (MainView) please share the screenshot for storyboard view also – Van Jul 2 at 11:14 ...

How to design below view [closed]

Image
How to design below view [closed] can u tell me, guys, How should I design below view, click on the tab bar that black view appears on a remaining tab bar view controller? Thank you Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question. You can use side menus like these github.com/fahidattique55/FAPanels github.com/vladislav-k/VKSideMenu github.com/balram3429/btSimpleSideMenu – Tejas Ardeshna Jul 2 at 9:47

Folder-button for a galleryapp (for example like )

Folder-button for a galleryapp (for example like ) At the moment I am trying to make a galleryapp with swift but I have only problems with it. Does anyone know of a starting point how to program a button on which you can create a photo album folder? What do you have to pay attention to? What kind of answer are you looking for? – Alexander Jul 2 at 0:24 If anyone knows a basically methode to program a button how I can create a foldern for new album folders – Henrik Jul 2 at 5:57 Well those are 2 separate parts, each of which could be pages of text. What have you tried to do to figure this out? – Alexander Jul 2 at 6:21 ...

Make UIButton accessible in Interface Builder

Image
Make UIButton accessible in Interface Builder I'm working on a little project which adds a little bar on the bottom of the screen, similar to UITabBar (see screenshot below). It's an @IBDesignable class. The blue boxes you can see are buttons with placeholder images. Now my question is, can I somehow open up these buttons to the IB as well? Like when I click one of the boxes I get the attribute inspector for that specific button? Thanks in advance UITabBar @IBDesignable Well, if every button has it's own xib, you can edit them there. – Sulthan Jul 1 at 11:02 1 Answer 1 Sorry I miss understood the question. No you can't have a UIButton as an attribute in the interface builder. I believe @IBInspectable only supports a certain group of typ...

Node Js value not showing in notification when testing

Node Js value not showing in notification when testing I am making a notification using firebase cloud functions with node js and my app made on swift this is my payload var payload = { notification: { title: (goOfflineTimePeriod,"Inactive for minutes you are now offline"), body: "Time period for inactive log off can be changed in your settings" though my notification my notification only shows as; "Inactive for minutes you are now offline", "Time period for inactive log off can be changed in your settings" so the variable; goOfflineTimePeriod does not show in the notification I am only new to node js is there a reason why "goOfflineTimePeriod" does not show in the notification? here is my full node js function code; exports.goOfflineAlert = functions.firestore .document('/goneOffline/{uid}') .onCreate((snap, context) => { var db = admin.firestore(); var uid = context.params.uid; const newValu...

CGImageRef is nil?

CGImageRef is nil? I'm trying to take pictures in my app using AVFoundatin. In the didFinishProcessingPhoto block I run some code to gather the image data and create an image to show in the preview screen. Code included below: didFinishProcessingPhoto func photoOutput(_ output: AVCapturePhotoOutput, didFinishProcessingPhoto photo: AVCapturePhoto, error: Error?) { if let error = error { print("Error capturing photo: (error)") } else { let photoData = photo.fileDataRepresentation() if let currentData = photoData { let dataProvider = CGDataProvider(data: currentData as CFData) let cgImageRef = CGImage(jpegDataProviderSource: dataProvider!, decode: nil, shouldInterpolate: true, intent: CGColorRenderingIntent.defaultIntent) let image = UIImage(cgImage: cgImageRef!, scale: 1.0, orientation: self.getImageOrientation(forCamera: self.videoDeviceInput.device.position)) let containerView = PreviewPhotoC...

Disabling zooming on webview

Disabling zooming on webview I've searched around, but I couldn't find how to disable zooming in iOS. I have this in my viewDidLoad() but it doesn't do anything. viewDidLoad() webView.scrollView.isMultipleTouchEnabled = false; Any ideas? 2 Answers 2 You can disable zooming like this: webView.scalesPageToFit = NO; webView.multipleTouchEnabled = NO; I'm trying to disable zooming though, not scrolling – Sam 5 hours ago @Sam Sorry, I misread the question. – hev1 5 hours ago no worries, but isn't this Obj-C? Cause they spew errors saying: Value of type 'WKWebVi...

access particular set of pixels MTLTexture in melal

access particular set of pixels MTLTexture in melal I created a MTLtexture using UIImage data as follows. var texture = metalView.currentDrawable!.texture let uiImg = createImageFromCurrentDrawable() guard let device = metalView.device else { fatalError("Device not created. Run on a physical device") } let textureLoader = MTKTextureLoader(device:device) let imageData: NSData = UIImagePNGRepresentation(uiImg)! as NSData texture = try! textureLoader.newTexture(data: imageData as Data, options: [MTKTextureLoader.Option.allocateMipmaps : (false as NSNumber)]) what I need to do is change pixels color in MTLTexture.Not all of them.So Is it possible to access particular set of pixels in MTLtexture and write into it in metal? 1 Answer 1 Yes, as a look at the MTLTexture documentation would have shown you. You can use one of the getBytes() methods to copy a region of texture data ou...

How can I subclass UISegmentedControl having custom designated initializer?

How can I subclass UISegmentedControl having custom designated initializer? Seems like a trivial issue but I am not able to make this compile. Neither in playgrounds nor in normal swift ios projects. (Please note I am not using Storyboards that's why I don't need / care about the init?(coder) part..it;s jsut it has to be include otherwise the complier complains about it.) class SegmentedControl: UISegmentedControl { let configuration: [String] required init(configuration: [String]) { self.configuration = configuration super.init(items: configuration) } required init?(coder aDecoder: NSCoder) { fatalError() } } let x = SegmentedControl(configuration: ["a","b"]) It is complaining about not having the deisignated initializer implemented. Fatal error: Use of unimplemented initializer 'init(frame:)' for class '__lldb_expr_167.SegmentedControl' I don't understand what is going on here. Isn...

Cannot disabled rotation on iPad

Image
Cannot disabled rotation on iPad The App has been released to public for months without any problem. But recently I found it can rotate screen on iPad when running iOS 9 or later. And it works without such problem on iPhone. Is it a bug of iOS 9? or I make something wrong? override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask { return UIInterfaceOrientationMask.Portrait } override func shouldAutorotate() -> Bool { return false } Can you choose the "Devices" is "iPad", and what is "Device Orientation" show up? – anhtu Oct 24 '15 at 2:11 @anhtu Wow, you're right! The problem solved. It's been working good on iOS 8, so I thought it as a correct setting ;-( . Can you post the answer in "Answer Your Question" so that I can accept ...

Link private key from secure enclave to provisioning profile

Link private key from secure enclave to provisioning profile I need to link my private key stored in the secure enclave to a certificate in a provisioning profile. Does anyone have experience with that and can help me out how to do that? As of now my knowledge is that this is quite hard to achive, because the private key in the secure enclave only can accessed from the application which have created the key pair. But I definitely need a solution for this. Otherwise I'm not able to connect to the WPA2 Enterprise network and use our vpn. The best solution for me would be, if there is a solution written in swift, because I create my key pair in swift and so I don't have different languages in my project. But if anyone has a solution in another language, I can change my project language. By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and coo...

Mark successful siesta response as error

Mark successful siesta response as error I'm working with a really strange (and nasty) API that I have no control over, and unfortunately when an invalid request is made, instead of responding with a 4xx status, it responds with a 200 status instead. With this response, it also changes the response body from the usual XML response to plain text, but does not change the content type header. You can imagine how annoying this is! I've got Siesta working with the API and the fact that it is no actually RESTful in the slightest, but I'm unsure how to get the next part working - handling the unsuccessful requests. How do I go about transforming a technically valid and successful 200 response, into an error response? Right now I have the following setup: configure("/endpoint") { $0.mutateRequests { req in ... perform some mutation to request ... } $0.pipeline[.parsing].add(self.XMLTransformer) } configureTransformer("/endpoint") { ($0.content as API...

Updating a integer as a label in swift

Updating a integer as a label in swift I want to change the number value of a label by pressing a button. I used to get errors saying you can't put a number in a string, so, I did string(variable). It now displays the basic number, 1, but when I click it, it doesn't update! Here is how I set up the variable: First, I set up the button, to IBAction. Here is the code inside of it: @IBOutlet weak var NumberOfExploits: UILabel! @IBAction func exploiter(sender: AnyObject) { var hacks = 0 hacks += 1 NumberOfExploits.text = String(hacks) } Can someone help be find out how to get it to change numbers? variable += 1 except second line? – SwiftStudier Aug 29 '15 at 17:20 3 Answers 3 First: let is used for constants, these can not be chan...

How to center table footer view in container programmatically using NSLayoutConstraint?

How to center table footer view in container programmatically using NSLayoutConstraint? I am building a screen for an app which has favorites. This screen will display the list of items that a user has favorited. This list is going to be displayed in a table view, pretty vanilla stuff. I am trying to add a little code for the empty state of the list, when no favorites have been added yet. I'd like to put a UIView in the tableFooter and then put a UILabel in the center of that view. I want the view to take up all the available space within the screen. UIView tableFooter UILabel So far this is what I have: self.tableView.tableFooterView = buildTableViewFooter() Pretty self-explanatory. func buildTableViewFooter() -> UIView { let footer = UIView(frame: self.tableView.frame) let label = UILabel() label.text = "Use the heart icon to add favorites" label.font = UIFont.italicSystemFont(ofSize: 21.0) label.textColor = UIColor.lightGray label.textAlignment = .cen...

CLLocation Timestamp is always zero

CLLocation Timestamp is always zero The CLLocation timestamp is always zero on iPhone 6+, IOS 11.4, Xcode 9.4.1. Latitude: 30.598748 Longitude: -97.820877 Altitude: 308.921658 HAccuracy: 10.000000 VAccuracy: 4.000000 Timestamp: 0.000000 <====== Is there some setting that will give me accurate timestamp? Here is the code that prints it: print("Latitude: (String(format: "%.6f", location.coordinate.latitude))") print("Longitude: (String(format: "%.6f", location.coordinate.longitude))") print("Altitude: (String(format: "%.6f", location.altitude))") print("HAccuracy: (String(format: "%.6f", location.horizontalAccuracy))") print("VAccuracy: (String(format: "%.6f", location.verticalAccuracy))") print("Timestamp: (String(format: "%.6f", location.timestamp as CVarArg))") 1 Answer 1 The ...

UISegmentedControl maintain aspect ratio on image

Image
UISegmentedControl maintain aspect ratio on image I'm having a hard time making images on a UISegmentedControl keep their aspect ratio and not scale to all sides. Here's what it looks like: The images are 100X100(except nr 6 gonna replace soon) and I want them to maintain the aspect ratio. I have tried: self.segment.contentMode = .ScaleAspectFit //and: self.segment.contentMode = UIViewContentMode.Center Are there a way I can target the UIImageView in the segment..that way I can set the contentMode..right? Or is there another approach? Thanks 3 Answers 3 segmentedControl.subviews.flatMap{$0.subviews}.forEach { subview in if let imageView = subview as? UIImageView, let image = imageView.image, image.size.width > 5 { // The imageView which isn't separator imageView.contentMode = .scaleAspectFit } } Please add an explanation. ...

Unable to use Swift object's variables in Objective-C View Controller

Unable to use Swift object's variables in Objective-C View Controller I am facing a problem accessing variables of a class written in Swift from a view controller written in Objective-C. I have already created the Bridging Header and I have successfully sent the Swift object from a view controller written in Swift to another one written in Objective-C. The problem is that I want to access the variables of the object but I get the following error: Property 'variableName' cannot be found in forward class object 'className' . Here is the class which I am trying to access its variables: import Foundation import UIKit import SwiftyJSON @objcMembers class SwiftObject: NSObject { // MARK: - Variables var id: String var name: String var contact: SwiftSubObjectA var location: SwiftSubObjectB var categories: [SwiftSubObjectC] = // MARK: - Initializers init(withJSON json: JSON) { self.id = json["id"].stringValue self.na...