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

How to create an array of SCNNode in swift
How to reject arrays with unwanted number range
Ruby Array Errors. Input won't enter array issue
Writing an Int-Array to a text file
What is the best way to save/load contents of array to file?
D: Creating an array of templated objects
cURL post json data, json array and image files REST api testing
Tcl array sorting based on values
How do I get all the values from a hash that are in an array?
Get an array dynamicaly from a factory
How to split a string by new lines in Swift
VB.net how to serialize list / array of json objects
How do I convert this hash to an array of hashes?
Define a next_in_line method on Array that takes the element at the beginning of the array and puts it at the end
Best way to calculate means within a MATLAB array based on other values in the array?
Parse the xml array and store the data into array or dictionary using swift

Categories

HOME
caching
shopify
vhdl
freepascal
paramiko
laravel-5.3
json-ld
windows-store-apps
phpstorm
wampserver
apple-numbers
xtext
java-home
actionscript-2
height
diagram
getorgchart
wordpress-theming
postmessage
lstm
spring-cloud-config
ssms-2016
android-toolbar
cairo
grub2
ios10.3
android-fragmentactivity
pycrypto
statusbar
apple-tv
url.action
shopping-cart
compare-and-swap
net-snmp
emv
widevine
unpack
partial-application
multichoiceitems
mangodb
invoke-command
oracle-xml-db
transient
hashcat
deepstream.io
ntfs-mft
nashorn
tripwire
spring-bean
powermta
ivona
filepath
proof
drawingarea
defold
quintus
castle-dynamicproxy
easing
update-site
mongoose-populate
children
try-finally
metalsmith
achievements
dac
asynccallback
java.util.calendar
persistence.xml
data-import
affix
uialertview
anti-patterns
webhdfs
urn
ffprobe
hiera
tcpreplay
omnifocus
sortable
emma
phpdocx
kraken.js
flash-cc
db4o
dynamic-proxy
sqljdbc
magicalrecord-2.2
robospice
astyanax
image-zoom
manage.py
socketstream
enumerators
moq-3
autostart
gdt
nssavepanel
electronic-signature
testunit
associative
server-error
grooveshark
filetime
openwysiwyg
integer-promotion
dotproject





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