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 get the length of a report's GroupingLevel array in VBA
Q2: AttributeError: 'builtin_function_or_method' object has no attribute 'size'
How can I make the following code into a 2D array?
How to write from an array to another array in excel vba
How to store variables from loop to a file
Add a new value to array
Segmentation fault with array indexing in Fortran
Printing a ruby array with zero formatting
how to store a list in a single array index
Minizinc: create an array of int pairs
Given an array of integers, where every number appears thrice except one number appears twice, find the number that appears twice?
How to match value against array and set variables?
Empty array using scan functrion ruby
How to reference hash.values created array
Add an Array of length x to value in key : value hash using Ruby
Indexing Double Float Array Swift

Categories

HOME
arrays
google-apps-script
sidekiq
ibm-watson-cognitive
udp
elixir
sed
voip
google-tag-manager
boost-thread
angular2-routing
smartphone
qpython3
google-sheets-api
amazon-product-api
travis-ci
apple-numbers
value
file-io
android-viewpager
xamarin-studio
onsen-ui2
spinnaker
cpanel
rebol2
scala-native
yeoman-generator
off-canvas-menu
saiku
prestodb
google-maps-android-api-2
hhvm
ghost-inspector
avplayeritem
richfaces
iup
piwik
qsub
novnc
badge
continuous-deployment
maximo
chrome-native-messaging
data-conversion
pitest
websauna
pep8-assembly
picturebox
graph-databases
pdflatex
m2e
nodeclipse
autocompletetextview
liquid-xml
mongoexport
twiki
bing-translator-api
datalog
google-account
intersystems-ensemble
ivona
filepath
double-buffering
floor
spring-data-hadoop
crystal-reports-8.5
jexl
fontconfig
addin-express
visual-studio-templates
gulp-typescript
settimeout
verbose
packagemaker
kendo-combobox
spring-lemon
scriptlet
loopj
loose-typing
insert-into
wikitext
fabric-twitter
playscape
sparse-file
git-checkout
mdm-zinc
belongs-to
proximity
grunt-contrib-concat
em
snmp4j
bullet
android-looper
edit-in-place
java.util.date
bigint
cilk-plus
adomd.net
vertical-scrolling
maven-ant-tasks
datacontract
gtk2hs
for-xml-path
ruby-debug
chatroom
windows-controls





Mobile Apps Dev
Database Users
javascript
java
csharp
php
android


MS Developer
developer works
python
ios
c
html
jquery


RDBMS discuss