arrays


How to add a date and time prefix to an array on Swift


The code listed below puts the text prefix car before each int array entry.
date | 2017-05-07 16:58:07 +0000:2,
var arrayOfInt = [Int]()
let cars = arrayOfInt.map { "car \($0)" }
label.text = String(describing: cars)
All I want to do is replace car with the date and time for each array entry when printed out.
Just append the date value in every iteration. For the time of creation just use create a new instance of Date.
To format the output of the date, use the DateFormatter. It allows you display the current time any way you like it.
var arrayOfInt = [1, 2, 3, 4]
let cars = arrayOfInt.map {
"date | \(Date.formattedNow()) \($0), "
}
print(String(describing: cars))
extension Date {
// Declare a static variable on `Date`, where you can modify your date output
static func formattedNow() -> String {
let now = Date()
let dateFormatter = DateFormatter()
// You need to update this property of the formatter, if you would like a different format
// For formats, see: http://nsdateformatter.com/
dateFormatter.dateFormat = "yyyy MMM EEEE HH:mm:ss"
dateFormatter.timeZone = TimeZone(identifier: "UTC")
return dateFormatter.string(from: now)
}

Related Links

Simple MATLAB Script
forEach loop in Angular 2
Python loop to print salaries within range of the average
How to display this data in twig
How to properly parse a dictionary array
Sort array [[String: Any]] alphabetically in swift 3.0 [duplicate]
In Ruby, how do I execute “select_with_index” on an array?
Is it possible to turn an array to a Result<> in Realm?
MongoDB resolve each ObjectId in an array field to an object from another collection
Play framework, parse json array from request
Swift array of Generics with protocols [duplicate]
How to reverse a given array of numbers in Python 3?
Saving an array of Integers using UserDefaults
delphi Send a file as byte array to a Rest service
Most frequent element in an array (bash 3.2)
User defined function changing each value in an array

Categories

HOME
sharepoint
jsf
erlang
bing
fparsec
laravel-5.2
windows-store-apps
csvhelper
couchdb-2.0
orientation
console
histogrammar
java-home
user
onenote-api
pca
powershell-v3.0
cockroachdb
data-synchronization
datagrip
rapidjson
reduction
cairo
prestodb
flexlm
styles
ip-camera
koa
countif
osmdroid
ui5
google-api-dotnet-client
pep8-assembly
clockwork
construct-2
nlb
bigcartel
es-shell
active-model-serializers
flex4.5
socketscan
viewgroup
react-native-router-flux
google-account
intersystems-ensemble
python-idle
estimation
mouseclick-event
openh264
push-diffusion
activeweb
update-site
software-product-lines
foxit
fps
fill
self-hosting
document-oriented-db
selendroid
textkit
mogrify
graphical-logo
ubercart
sparse-file
apache-mina
musl
multipleselection
inputaccessoryview
line-numbers
libsndfile
candidate-key
ibmsbt
hidden-field
ghostdoc
proxies
picat
visual-studio-addins
java.util.date
leptonica
javascriptmvc
vmware-server
dynamics-ax-2009
soa-suite
fieldset
bulbs
qsqltablemodel
macruby
expression-evaluation
jpf
flexicious
paintcomponent
phpcrawl
junit3
grooveshark
plinq
evb

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App