swift - Using the Map Method to Call a Class Method -


i learning map method in swift. standard definition

the map method takes function (transform), , returns array containing results of calling transform on each element in array.

this makes sense. if wanted add text string each string element in array following.

var stringarray = ["blue", "green", "brown", "white"] var newstringarray = stringarray.map({"\($0)color"}) 

this adds "color" each element.

my question has proper use of map function. if use create number of objects class methods acceptable use. example if have array number of objects used create new objects, calling class function map method ok? works want make sure it's not bad practice.

xmlparseddataarray!.map({article.createfloarticlewithstructure($0, inmanagedobjectcontext: self.articlecontext)}) 

each element in xmlparseddataarray structure defined below.

struct datetitlelink {     var date : nsdate?     var title : string?     var link : string? } 

the createfloarticlewithstructure method create article object , store in core data.

technically not transforming each element of array, using map method call class function.


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -