How to remove multiple spaces in Strings with Swift 2

In Swift 2, join has become joinWithSeparator and you call it on the array. In filter, isEmpty should be called on the current iteration item $0. To replace whitespaces and newline characters with unique space characters as in your question: extension String { func condenseWhitespace() -> String { let components = self.componentsSeparatedByCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet()) return components.filter { … Read more

Extension of a nested type in Swift

It seems like this problem is related to SR-631. I’ve encountered similar a issue, I guess the complier is trying to process the file where you extend the nested class before the one where it’s defined. Therefore you have this error saying that that A has no member B. The solution I’ve found is to … Read more

Using the split function in Swift 2

split is a method in an extension of CollectionType which, as of Swift 2, String no longer conforms to. Fortunately there are other ways to split a String: Use componentsSeparatedByString: “ab cd”.componentsSeparatedByString(” “) // [“ab”, “cd”] As pointed out by @dawg, this requires you import Foundation. Instead of calling split on a String, you could … Read more

Swift’s guard keyword

Reading this article I noticed great benefits using Guard Here you can compare the use of guard with an example: This is the part without guard: func fooBinding(x: Int?) { if let x = x where x > 0 { // Do stuff with x x.description } // Value requirements not met, do something } … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)