ios - 2 arrays into one dictionary while maintaining the indexes -


i have 2 separate arrays want import dictionary. order extremely important because both arrays must match in index

struct myvariables {     static var users:nsarray!     static var img:nsarray! }      var data = searchvc.getdata()     myvariables.users = data.users;  //array 1  (key)     myvariables.img = data.img;      //array 2   // goal insert these arrays dictionary while maintaing matching indexes on both arrays // dictonary (myvariables.img, key: myvariables.users) 

the key in dictionary in swift must hashable. i.e., not anyobject.

assuming can replace of untyped swift arrays, or cast them so:

struct myvariables {     var users:array<anyobject>     var img:array<string> } 

then can iterate through 1 array using preferred swift method , access second using indexing:

var dictionary = dictionary<string, anyobject>()  (index, element) in enumerate(myvariables.img) {     dictionary[element] = myvariables.users[index] } 

Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -