Creating an array of objects for dictionaries
var DrugArray:[Drug] = []
var drugs:[String] = []

for i in array {
    if contains(drugs, i["drugName"]! as String) {
        continue
    } else {
        drugs.append(i["drugName"]!)
        DrugArray.append(Drug(name: i["drugName"]!))
    }
}

for a in DrugArray {
    for i in array {
        if i["drugName"]! == a.name {
            a.dosage.append(dose: i["dose"]!, time: i["time"]!)
        }
    }
}



So, now that we've cleaned up the code and made it more readable, let's talk about some refactoring we can do.

The first thing I notice is that your nested loop at the bottom is entirely unnecessary.  We can do all of that logic in the top loop.

We're also doing a lot of forced unwrapped... which you really don't want to do.  All this is going to do is result in a crash in your app eventually.

We're also using single letter variable names which invokes no meaning to the reader.  These loops are short... for now.  If &amp; when the contents of the loop grows (the top loop is already close to being at the point), you'll start to see the value in having meaningful variable names.  It helps you remember exactly what the variable represents.  Better variable names is just one part of making your code self-documenting.

And ultimately, as Mario Zahone's answer points out, what we clearly need is a dictionary rather than an array (and a separate array to keep track of what's already been tracked).

Finally, repeatedly appending to a collection almost always results in poor performance.  If there's not enough space in the collection's current memory location for one more item, the entire collection has to be copied into a new memory location, which is an expensive task.  In a loop with lots of iterations, this is likely to happen multiple times.  So, when we can guess at a good minimum size, we want to go ahead and make sure our collection is allocated in a large enough memory space.

So, taking all of these things into account, the final implementation of our code probably looks something like this:

var drugs = [String:Drug](minimumCapacity: array.count)

for drugDictionary in array {        
    if let
        drugName = drugDictionary["drugName"],
        drugDose = drugDictionary["dose"],
        drugTime = drugDictionary["time"] {

        drugs[drugName] = drugs[drugName] ?? Drug(name: drugName)
        drugs[drugName]?.dosage.append(dose: drugDose, time: drugTime)
    }
}


If we really want an array, we can always fetch one from the dictionary:

let drugArray = drugs.values