A while back I made a custom String struct (see [github repo][1]) because of the difficulties in dealing with Mongolian Unicode rendering when using Swift `String` or `NSString` (see [this question][2] and the accepted answer for more details). The struct is an array of `UInt32` so that it represents a string of Unicode scalar values.

The most difficult part (see [here][3] and [here][4] for my StackOverflow questions at the time) was making it conform to the Hashable Protocol so that it could be used as a Dictionary key.

For all that I can tell, everything has been working fine. However, since there was not a lot of documentation and guidance available about implementing the Hashable Protocol, I wanted to make sure that I did it right. Here is the relevant code:

    struct ScalarString: SequenceType, Hashable, CustomStringConvertible {
        
        private var scalarArray: [UInt32] = []

        // ...
    
        // hashValue needed to implement Hashable protocol
        var hashValue: Int {
            get {
                
                // DJB Hash Function
                var hash = 5381
                
                for(var i = 0; i < self.scalarArray.count; i++)
                {
                    hash = ((hash << 5) &+ hash) &+ Int(self.scalarArray[i])
                }
                
                return hash
            }
        }
    
    }

    // Hashable also needs struct to conform to Equatable protocol
    func ==(left: ScalarString, right: ScalarString) -> Bool {
        
        if left.length != right.length {
            return false
        }
        
        for var i = 0; i < left.length; ++i {
            if left.charAt(i) != right.charAt(i) {
                return false
            }
        }
        
        return true
    }


  [1]: https://github.com/suragch/MongolAppDevelopment-iOS/blob/master/Mongol%20App%20Componants/ScalarString.swift
  [2]: http://stackoverflow.com/questions/31272561/working-with-unicode-code-points-in-swift
  [3]: http://stackoverflow.com/questions/31438210/how-to-implement-the-hashable-protocol-in-swift-for-an-int-array-a-custom-strin/
  [4]: http://stackoverflow.com/questions/31664159/how-to-handle-hash-collisions-for-dictionaries-in-swift/