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

Ionic 2 Angularfire2 and Firebase item to array
Sorting Array / Dictionary by duplicates in Swift
Mysterious “extra argument in call” error in Array extension method [duplicate]
Recursively setting hash keys from an array of keys
Putting the count of a loop in an array index
How do I compare numbers in a string array?
Giving structure to a flat data array
Why is an array sometimes used as a key in JSON when this array has only one entry that contains a dictionary?
How to get value of array key from query in golang
Strongloop Loopback: where filter with two arrays
Mapping Json with nested array using ObjectMapper Swift 3
how to calculate the values of a 4d array by bilinear interpolation without 4 'for' loop
How to compare a random UIColor to colors in an array of colors in swift?
Express.js req.body parametr array
how to parse json array in android using volley
how to get one dimensional vector from an array in vba

Categories

HOME
arrays
sas
cil
sass
signalr
elixir
vhdl
blockchain
facebook-graph-api
backup
steam
flyway
specflow
schemacrawler
google-classroom
x11
cartodb
nixos
xlsx
scaling
google-openid
linq-to-sql
rails-activerecord
deb
onsen-ui
myob
novnc
badge
non-deterministic
pcre
encase
protobuf-net
nsurlconnection
large-data
wfp
socketpair
flex4.5
ical-dotnet
ssh.net
pdftk
service-fabric-stateful
scalafx
worker
w3-total-cache
proof
instruction-set
httplib2
build-process
pdflib
mongoose-populate
instruments
faraday
altbeacon
except
sonarqube5.3
vips
sem
urn
ffprobe
cpu-cores
ticket-system
cloudpebble
gmaps4rails
line-numbers
scala-2.11
ibmsbt
grunt-express
snmp4j
iostream
ember-addon
dache
aquafold
config-files
reserved-words
hamsterdb
healthvault
pep8
xslkey
mozart-mvc
text-services-framework
selectonemenu
text-size
qtembedded
for-xml-path
chatroom
hadoop-plugins
sitemappath
longjmp
writing

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