Swift Integer

An integer (meaning “whole” from a Latin integer) is a number that can be described without a fractional part. For example, 3, 4, -7 and -1024 are integers, but 0.15, 1/2 and √5 are not integers. Signed (positive, zero, or negative) or unsigned (positive or zero) integers. Swift provides signed and unsigned integers in 8, […]

Share:
Continue Reading

Swift4 – Using URLSession to get current server time

  func returnServerTime(completionHandler:@escaping (_ getResDate: NSDate?) -> Void){ let stringurl = “http://” + “Your Server IP” let url = NSURL(string: stringurl) let task = URLSession.shared.dataTask(with: url! as URL) {(data, response, error) in let httpResponse = response as? HTTPURLResponse if let contentType = httpResponse?.allHeaderFields[“Date”] as? String { let dFormatter = DateFormatter() dFormatter.dateFormat = “EEE, dd MMM […]

Share:
Continue Reading

Swift4 – Using TextOutputStream to write log text file to disk

To log your own application events, you need to create your own log file. This is the most common way to create a text file and save it to disk on an iOS device like an iPhone, iPad, or iPod.   struct Log: TextOutputStream { func write(_ string: String) { let dFormatter = DateFormatter() dFormatter.dateFormat […]

Share:
Continue Reading