can't unsafeBitCast between types of different sizes in swift can't unsafeBitCast between types of different sizes in swift xcode xcode

can't unsafeBitCast between types of different sizes in swift


var mp3Files: Array<String!>!

Wow, that's a lot of exclamation points.... They're not needed.

var arrayForSearch = mp3Files as! [String]

And the type of mp3Files can never be the same as [String], so you can't force-cast between them (and would crash if it let you).

You're using implicitly unwrapped optionals way too often. They are only needed in some special cases. Just change mp3Files to [String] (in which case you won't need the as! at all; you shouldn't need as! very often either).

Similarly, arrayFiles (which you never use), should just be [NSURL], not Array<NSURL!>!.


Here I try same code as you given:

import UIKitclass ViewController: UIViewController {    let strArr = ["a","b","a","d","f","f","b"]    override func viewDidLoad() {        super.viewDidLoad()        filter()    }    func uniq<S : SequenceType, T : Hashable where S.Generator.Element == T>(source: S) -> [T] {        var buffer = [T]()        var added = Set<T>()        for elem in source {            if !added.contains(elem) {                buffer.append(elem)                added.insert(elem)            }        }        return buffer    }    func filter() {        var arrayForSearch = strArr        var newArr = uniq(arrayForSearch)        println("filtered array \(newArr)")    }}

And OutPut in console:

filtered array [a, b, d, f]

My be there is a problem when you are casting your array to [String] so check it once again.