How should my data be stored? – Swift

Maybe this is a very basic question, but I have struggled to find a suitable answer. My app will contain a list of fictional characters. Each character has a name, a year of release, a unique ID number, and an accessory/weapon.

The user will not be able to edit, add, or delete characters. There will be about 1500 entries. Each Table View Cell will state the name of the character that when clicked will transition to a View Controller with all of the information.

My question is how do I put this information into my app that then can be used to populate the Table View? I tried using encodable and decodable but that has significantly slowed down my app. I looked into adding the information into a plist, but I still don’t know if that is the best way.

Onfido sandbox error 422 Unprocessable Entity Validation

I’m trying to create a check in Onfido sandbox environment and it’s working fine when I use curl or python code while I’m receiving error 422 when I do the same request using swift from iOS.
here is the code that is confirmed to work in python:

def identity_check(self, applicant_id: str) -> dict:
        return self._post(
                'type': 'express',
                'reports[][name]': 'identity',
                'reports[][variant]': 'kyc',

and this is the swift code that gives me error 422:

 func executeCheck() {
        let headers: HTTPHeaders = [
            "Authorization": "Token token=\(token)",
            "Accept": "application/json",
        let parameters: [String: Any] = [
            "type": "express",
            "reports[][name]": "identity",
            "reports[][variant]": "kyc"
            method: .post,
            parameters: parameters,
            encoding: JSONEncoding.default,
            headers: headers).validate().responseJSON { (response: DataResponse<Any>) in
                guard response.error == nil else {

How to detect keyboard height without input accessory view?

I have a keyboard with a custom accessory view. I can get its height by registering for keyboardWillShowNotification notification:

NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShowNotification(notification:)), name: NSNotification.Name.UIKeyboardWillShow, object: nil)

And the callback handler:

@objc fileprivate func keyboardWillShowNotification(notification: NSNotification) {
    guard let keybrdEndFrame = (notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue else {
    print(">>>> height: \(keybrdEndFrame.size.height)")

However, in this the keybrdEndFrame.size.height gives me the height of the keyboard + the height of the accessory view. While in my particular case I know the height of the accessory view (since I have implemented it), so I can calculate the height of keyboard, I would like to know if there is a more generic solution in which I could decouple the calculation from the custom accessory view.

So my question is – is there a way to retrieve the height of the keyboard without the accessory view? Or alternatively, is there a way to retrieve just the height of the accessory view currently presented with the keyboard?

What is the standard approach to building cross-platform mobile libraries? [on hold]

I’m an Android developer looking to build out libraries that can be used across Android and iOS, but unsure what the “best” approach for this is.

Some libraries I’d like to build are:

  1. Exposing a REST API to both clients.
  2. Sharing a common set of data models.
  3. Reusable UI components for a consistent user experience.

I think React Native would be a good approach for the UI, but what is the generally accepted approach for building out shared logic across platforms? Is that something that can be done using React Native? Can libraries built through Xamarin be easily reusable across either platform? Ideally, I’d like to distribute these libraries through Gradle and CocoaPods as well.

UIButton with gradient border and rounded corners

What I am trying to get is the a custom UIButton that has a gradient border (just the border is gradient) and rounded corners. I almost got to where I wanted to be, but having issues with the corners.
Here is what I currently have:
enter image description here

Here is my code:

override func viewDidLoad() {

    let gradient = CAGradientLayer()
    gradient.frame =  CGRect(origin:, size: self.myButton.frame.size)
    gradient.colors = [,]
    gradient.startPoint = CGPoint(x: 0.0, y: 0.5)
    gradient.endPoint = CGPoint(x: 1.0, y: 0.5)
    gradient.cornerRadius = 15

    let shape = CAShapeLayer()
    shape.lineWidth = 5
    shape.path = UIBezierPath(rect: self.myButton.bounds).cgPath
    shape.strokeColor =
    shape.fillColor = UIColor.clear.cgColor
    shape.cornerRadius = 15
    gradient.mask = shape

    self.myButton.clipsToBounds = true
    self.myButton.layer.cornerRadius = 15

So the question is how do I display corners with gradient?

Calculating percentage between 2 Swift Date objects

I have an app with a timer that shows percentage between the creation date of a reminder to the end date.

I have 2 parameters (for example):

creationDate : 2018-02-16 17:06:10 UTC
‘endDate’ : 2018-02-16 15:07:09 UTC

The timer should show how much percent has passed between the 2 Dates.

I’ve tried:

let duration = self.creationDate.timeIntervalSince(self.endDate)
let timePassed = self.creationDate.timeIntervalSinceNow
let percent = (timePassed * 100) / duration

but the information I got was incorrect.

Does anybody know what’s wrong with my algorithm? Thanks!

Get an element that contains another element with a static text in iOS UITesting

How to build a query to get an element that contains another element by static text.

Example: Get the first table cell that contains a label with text “cool cell”

I need it because I have different cells and I want to get a cell that contains a specific text. Note that I’m interested to get the cell because I need to make sure that the cell contains another elements. The goal is to make sure that the cell with the title “I’m a cell” has also a label with text “cool”

Merge data locally & offline in iOS app with RealmSwift?

I’ve searched all over the internet for a tutorial on how to merge data in Realm DB! but actually I found nothing useful, Indeed no-one created a guide or tutorial on this topic.

I want to persist a book app contents locally in app but all the tutorials are on how to save the user “new data” in app and not about persisting and merging data in app such as a book app that have many chapters and includes long text materials that the user just want to read the contents(data) . .

I found out with Realm browser you can just edit the simulator’s data and it seems there’s no way to merge a Realm DB file with your app and finally publish it in App Store!

On the other hand I’m looking for a way to import long text data and some images to Realm and merge it with my app, so when user download the app, the user be able to see data in offline mode.

Thank you all for the time you’re spending on this