Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

288
Views
How to print/dump NSObject?

I have a

Crashlytics.sharedInstance().setObjectValue(loginAccount, forKey: "loginAccount")

I have access to SwiftyJSON Pod in my project, so I've tried

print(JSON(loginAccount))

I got

unknown

What should I do to make my dict more humanly readable ?


SessionAccount

import Foundation
import SwiftyJSON


public class SessionAccount : NSObject {

    var id             : Int?
    var username       : String?
    var password       : String?
    var accountType    : String?
    var role           : String?
    var privateVlan    : String?
    var guestVlan      : String?
    var timezoneOffset : Int?
    var loginTime      : Date?
    var cpe            : CPE?
    var cpeName        : String?
    var cpeProfiles    : [Profile] = []
    var deviceCount    : Int?
    var activeCount    : Int?
    var inactiveCount  : Int?
    var offlineCount   : Int?
    var profileDevices : [Device] = []
    var cpeDevices     : [Device] = []
    var lanSetting     : LANSetting?
    var alerts         : [Alert] = []
    var quarantineList : [String] = []

    override init() {
        super.init()
    }

    convenience init(_ record: JSON) {
        self.init()
        self.id = record["id"].int
        self.accountType = record["accountType"].string
        self.role = record["role"].string
        self.timezoneOffset = record["timezoneOffset"].int
    }

}
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You can use dump(self).

dump() doesn't return a string. It just prints out to the console,

output will be -

<SessionAccount: 0x000055957bfcd400> #0
  - super: Foundation.NSObject
  - id: nil
  - username: nil
  - password: nil
  - accountType: nil
  - role: nil
  - privateVlan: nil
  - guestVlan: nil
  - timezoneOffset: nil
  - loginTime: nil
  - cpeName: nil
  - deviceCount: nil
  - activeCount: nil
  - inactiveCount: nil
  - offlineCount: nil
  - quarantineList: 0 elements
over 4 years ago · Santiago Trujillo Report

0

Is SessionAccount really required to be a class which inherits from NSObject? If you use a struct print is going to print all members.

In a class you have to override description and return a string what you want to display for example

override var description : String {
    return "SessionAccount: \(username) - \(accountType)"
}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!