Posts

Post marked as solved
3 Replies
1.5k Views
Hi, So I have been recently work on some research for a Health Care application where HIPPA compliance is a requirement. I had done research into FireBase and that seemed good, but as of May 2018 it is not HIPPA compliant. I was looking around and Apple CloudKit seems like a good option, however I could not find any information from Apple's developer pages about CloudKit on whether it was HIPPA compliant or not?
Posted
by mkhan094.
Last updated
.
Post not yet marked as solved
10 Replies
5.3k Views
I'm working on parsing a JSON file into a dictionary: // JSON Payload File { "orderPlaced": "done", "prep": "pending", "shipped" : "pending" }Here is my code to make a dictionary from that file: if let path = Bundle.main.path(forResource: "JSONPayload", ofType: "json") { do { // Data from JSON file path let data = try Data(contentsOf: URL(fileURLWithPath: path), options: []) // JSON dicrtionary being made let json = try JSONSerialization.jsonObject(with: data) as! [String: Any] print(json) } catch let jsonErr { print("err", jsonErr) }Expected output: ["orderPlaced": done, "prep": pending, "shipped": pending]The actual output is: ["shipped": pending, "orderPlaced": done, "prep": pending]Is there a way I can re-order my dictionary or have it ordered from the start. I'm assuming the latter request might not be doable since dictionaires from my understanding are un-ordered. Maybe the only thing I can do is re-order after the dictionary is made, but how would i do that? Do I have to modify my JSON file and the Swift code or just one or ther other?
Posted
by mkhan094.
Last updated
.
Post marked as solved
2 Replies
2.5k Views
Hi,Does anyone know how to add images inline in a post. Sometimes I have a question and it is best explained with accompanying text and an image or screenshot. Do Apple Developer Forums even support images... if so, @AppleDeveloperForums... please add this feature.. Thanks!
Posted
by mkhan094.
Last updated
.
Post not yet marked as solved
2 Replies
727 Views
Hi,Working on a simple problem where I want to sum all the elements in an int array. All the numbers in the array are positive. I came accross the reduce method online and I noticed the following syntax:let items = [2, 4, 5, 7] let sum = items.reduce(0, +) // result is 18I understand that the first argument is the initial result (in my case 0). I'm having a hard time understand the nextPartialResult closure which is the second argument. I also don't understand the "+" syntax, I'm guessing that shorthand for summing all the elements in the array. I don't want to just use that code without understanding what it means...Any help would be appreciated!Thanks!
Posted
by mkhan094.
Last updated
.
Post marked as solved
4 Replies
3.3k Views
I had a question about the $0 syntax in Swift. Haven't had a chance to use it much, however, I am working with things like filter, flatmap, and compactmap, so I see them more often. Any documentation reference or resources on these topics would be super helpful in understanding!Thanks!
Posted
by mkhan094.
Last updated
.
Post not yet marked as solved
4 Replies
1.9k Views
Hi,I'm working on a project where I have tabular data provided in an excel file (.xlsx). I am trying to figure out how to bring in or model that data in Swift so I can query a specific row and column combination. I had a couple of thoughts on this:1. Use a third party library like CoreXLSX to read the data directly from the excel file2. I found Apple's MLDataTable API pretty interesting. Can this be used for non machine learning tasks? From the documentation, it looks like its use-case is for machine learning rather than being a general purpose data table class?Thanks!
Posted
by mkhan094.
Last updated
.
Post not yet marked as solved
1 Replies
1.1k Views
I am working on building a color wheel picker UI for an iOS app. While there are several great Color Wheels that the developer community has written, I am actually trying to build a Color Wheel from scratch to understand how these color wheels and UIs are made. One of the first things is figuring out how to convert HSB values to RGB. I made a quick Swift Playground to get started:// ColorExperiments Playground import UIKit // A HSB color where: // H = 5 degrees out of 360 degrees // S = 91% -> 0.91 // B = 100% -> 1.0 var hueColor = UIColor.init(hue: 5/360, saturation: 0.91, brightness: 1.0, alpha: 1.0) // The RGB equivalent should be // R = 255 // G = 42 // B = 23I tried looking into the UIKit documentation and online, maybe I missed it, but is there an API in UIColor that allows me to convert the HSB to RGB color? I found some third party functions. I'm guessing UIColor should have something since the Swift Playgrounds sidebar shows me the my hueColor variable as the RGB equivalent unless that's some private function that Apple is using.Thanks!
Posted
by mkhan094.
Last updated
.
Post marked as solved
2 Replies
419 Views
This is sort of based on some research I did into a method in Foundation. The method in question is decode(_:from:) and according to the developer docs, this method is:Declarationfunc decode<T>(_ type: T.Type, from data: Data) throws -> T where T : DecodableDefinitionReturns a value of the type you specify, decoded from a JSON object.In this method, Apple used T.Type for the first parameter. From a previous forum thread (see link below), I understand what T.Type means:T.Type is a notation to speicify a type which can hold a type object of T (not an instance of T)....My question is that I don't understand how would I know as a developer that I can add have this .Type syntax available to use. My first place was to check was in the Generics Docs, but no result. I'm sure it's documented somehwere, otherwise, how would anyone know how to use it?Any help on where this is documented would be appreciated, I'm just trying to understand this properly.Link to Previous Forum:h ttps://forums.developer.apple.com/thread/109664?q=Generics*P.S. I would reply to this thread listed above, however, I am having troubles accesing that thread... this is why I made this one!
Posted
by mkhan094.
Last updated
.
Post marked as solved
3 Replies
527 Views
I am working through a tutorial on URLSession and URLRequest and ran into an interesting block of code... my first instinct was that this was a closure but I'm not 100% sure... if it is, I havent seen one like this until now. I've been familraiizng my self with closure since they are used a lot in networking code especially things like completion handlers...Here is the code below... basically a URL is being constructed from a baseURLString decalred earlier and a relative path to a resource... Where I thought this was a closure was on line 36 where there is a pair of parantheses... Is this a closure syntaxt or some other special Swift syntax?let url: URL = { /** * A string that contains the relative path. In other words, this string * would be appended to the url made from the baseURLString to access a specific resource. * * For example, for the case .getPublicGists(), the relative path as described by GitHub is "gists/public". The resulting url * would be a combination of the baseURLString and this relative path: "https://api.github.com/gists/public". */ let relativePath: String? switch self { case .getPublicGists(): relativePath = "gists/public" } var url = URL(string: GistRouter2.baseURLString)! if let relativePath = relativePath { url = url.appendingPathComponent(relativePath) } return url }()
Posted
by mkhan094.
Last updated
.
Post marked as solved
2 Replies
480 Views
I am working through a tutorial on URLSession and URLRequest and ran into an interesting block of code... my first instinct was that this was a closure but I'm not 100% sure... if it is, I havent seen one like this until now. I've been familraiizng my self with closure since they are used a lot in networking code especially things like completion handlers...Here is the code below... basically a URL is being constructed from a baseURLString decalred earlier and a relative path to a resource... Where I thought this was a closure was on line 39 where there is a pair of parantheses... Is this a closure syntaxt or some other special Swift syntax?let url: URL = { /** * A string that contains the relative path. This path is relative to the base string. In other words, this string * would be appended to the url made from the baseURLString to access a specific resource. * * For example, for the case .getPublicGists(), the relative path as described by GitHub is "gists/public". The resulting url * would be a combination of the baseURLString and this relative path: "h ttps://api.github.com/gists/public". */ let relativePath: String? switch self { case .getPublicGists(): relativePath = "gists/public" } var url = URL(string: GistRouter2.baseURLString)! if let relativePath = relativePath { url = url.appendingPathComponent(relativePath) } return url }()
Posted
by mkhan094.
Last updated
.
Post marked as solved
2 Replies
534 Views
I am fairly new to computed properties and am trying to recongnize them in code samples... I came accross this in one of the tutorials I am learning on URLSession. Would this var method: String property be a computed property?var method: String { switch self { case .getPublicGists(): return "GET" } }Thanks!
Posted
by mkhan094.
Last updated
.
Post marked as solved
2 Replies
532 Views
Recently I came across a new way to unwrap optional via the Nil-Coalescing Operator and I found a use case of it during writing some code related to URLSession and URLRequest. The line of interest is line 04:var urlRequest = URLRequest(url: url) urlRequest.httpMethod = "PATCH" var headers = urlRequest.allHTTPHeaderFields ?? [:] headers["Content-Type"] = "application/json"So from reading the Swift guide, I have a good idea of what this operator is doing in the context of line04...1. Either it will unwrap urlRequest.allHTTPHeaderFields if it contains a value2. Returns [ : ] if urlRequest.allHTTPHeaderFields is nil3. [ : ] must match the type that is stored inside urlRequest.allHTTPHeaderFieldsSince urlRequest.allHTTPHeaderFields is of type [String:String], I am assuming that by entering [ : ] Swift inferred this dictionary to be of type [String:String] otherwise we would have to write this as the code below. I am also assuming that writing it both ways is acceptable?var headers = urlRequest.allHTTPHeaderFields ?? [String:String]Thanks!
Posted
by mkhan094.
Last updated
.
Post marked as solved
3 Replies
363 Views
I'm currently learning about closures and how they work and I came accross the following statement on Swift.org in the Closures Documentation:The parameters in closure expression syntax can be in-out parameters...I've never head of this concept of "in-out" parameters... what does this mean?Thank you.
Posted
by mkhan094.
Last updated
.
Post marked as solved
17 Replies
2.6k Views
I have a subview that I have placed inside my ViewController via IB. Inside that view, I want to draw a progress tracker composed of circles and lines using UIBezierPaths. In my subview, I do not want to draw the progress tracker edge to edge, instead, I want to have a nice visual padding... To do that, I did several things:1. Made a SizeRatios struct with constants that I developed to help me define the size of my circles, lines, and padding depending on the subviews height and width2. My next approach was to make a rectangular bezier path inside my subview (in this path, the progress tracker components will be draw in and bounded by the path. I have several questions: * Is my strategy so far in the right direction (drawing bezier paths inside an existing path)? * How do I access the coordinate space of the path and not the subview, I want to draw inside the path? * Would making a CGRect and drawing inside the corrdinate space of that be a good solution?I am specifically stuck on my makeElement() method, the points are based on the rectangular bezier paths coordinates, but the circle is being draw in the subview, I want to draw inside the rectangualar bezier path... Thanks in advance!!! 🙂Screenshot Link: h ttps://drive.google.com/file/d/1kM6nmyIiOtyNjB3B3NQOgwzXxdkLMCmw/view?usp=sharingimport UIKit class ProgressTrackerView: UIView { // Array for holding circular bezier paths var paths = [UIBezierPath()] // Number of circles to make, this will be later determined // by some automatic measn based on some server logic... for simplicity sake, this will // not go above 4. var numberOfElements = 4 // Stores stride points... see calculateStridePoints() method. // In a nutshell, stride points are used to draw circular bezier paths // inside the rectangular path. var stridePoints = [CGPoint()] // The bezier path that will be drawn into, possibly, maybe a CGRect? var progressTrackerRect: UIBezierPath = UIBezierPath() /** Computes and returns the `bounds.width` value of the `ProgressTrackerView`. */ var progressTrackerViewWidth: CGFloat { return bounds.width } /** Computes and returns the `bounds.height` value of the `ProgressTrackerView`. */ var progressTrackerViewHeight: CGFloat { return bounds.height } // Size Ratios // These were determined by doing some quick mockups in Keynote private struct SizeRatios { /** Ratio to set the width of the `progressTrackerRect` to be proportional to the width of the `ProgressTrackerView` */ static let progressTrackerRectWidthToViewWidth: CGFloat = 0.885 /** Ratio to set the height of a progress element proportional to height of the `ProgressTrackerView` */ static let progressElementHeightToViewHeight: CGFloat = 0.531 /** Ratio to set the height of a line proportional to the height of a progress element */ static let lineHeightToProgressElementHeight: CGFloat = 0.250 } /** Configures and returns a rectangular bezier path. The progress tracker (composes of circular elements and lines) will be drawn in the bounds of this bezier path.*/ func prepareRectForProgressTracker() -> UIBezierPath { /** Define the width and height of the progress tracker rectangle. */ let progressTrackerRectWidth = progressTrackerViewWidth * SizeRatios.progressTrackerRectWidthToViewWidth let progressTrackerRectHeight = progressTrackerViewHeight * SizeRatios.progressElementHeightToViewHeight /** Define the x and y coordinates of the rectangle */ let xRect = (progressTrackerViewWidth - progressTrackerRectWidth) / 2 let yRect = (progressTrackerViewHeight - progressTrackerRectHeight) / 2 /** The final rectangle to be returned */ let progressTrackerRectPath = UIBezierPath(rect: CGRect(x: xRect, y: yRect, width: progressTrackerRectWidth, height: progressTrackerRectHeight)) progressTrackerRectPath.lineWidth = 2.0 progressTrackerRect = progressTrackerRectPath return progressTrackerRect } func calculateStridePoints() { let subtractedValue = progressTrackerRect.bounds.width / CGFloat(numberOfElements * 2) let strideByConstant = progressTrackerRect.bounds.width / CGFloat(numberOfElements) for strideValue in stride(from: strideByConstant, to: progressTrackerRect.bounds.width + strideByConstant, by: strideByConstant) { let stridePoint = CGPoint(x: strideValue - subtractedValue, y: progressTrackerRect.bounds.midY) stridePoints.append(stridePoint) print(stridePoint) } } // This is where I am stuck... trying to draw only one path for now for testing purposes... // but how to i make sure that the arc center point is a poin in the rectangular bezier path and not the view... func makeElementAt() -> UIBezierPath { let circlePath = UIBezierPath(arcCenter: stridePoints[0], radius: (progressTrackerRect.bounds.height / 2), startAngle: 0.0, endAngle: CGFloat(2*Double.pi), clockwise: false) return circlePath } override func draw(_ rect: CGRect) { let color = UIColor.red color.setStroke() let progressTrackerRect = prepareRectForProgressTracker() progressTrackerRect.stroke() /// I know bad coding practice, drawRect is only for drawing, I'm just /// doing this to get the fundamentals working and will move this outta /// drawRect.. calculateStridePoints() let circlePathColor = UIColor.blue circlePathColor.setStroke() circlePathColor.setFill() let testCirclePath = makeElementAt() testCirclePath.stroke() testCirclePath.fill() } }
Posted
by mkhan094.
Last updated
.