What’s wrong here: Instance member cannot be used on type [duplicate]

The problem here is that you are using self before the class is fully initialised. You can either have a getter which will be called every time you access the variable or compute it lazily. Here is some code: class TableViewController: UITableViewController { let mydate = NSDate() var items : [(Int,Int,Int,String,NSDate)] { get { return … Read more

Override func error in Swift 2

You’re getting your first error because much of Cocoa Touch has been audited to support Objective-C generics, meaning elements of things like arrays and sets can now be typed. As a result of this, the signature of this method has changed and since what you’ve written no longer matches this, you’re given an error explaining … Read more

Swift: How to get everything after a certain set of characters

In Swift 4, use upperBound and subscript operators and open range: let snippet = “1111 West Main Street Beverly Hills, CA 90210 Phone: 123.456.7891” if let range = snippet.range(of: “Phone: “) { let phone = snippet[range.upperBound…] print(phone) // prints “123.456.7891” } Or consider trimming the whitespace: if let range = snippet.range(of: “Phone:”) { let phone … Read more

How do I check in Swift if two arrays contain the same elements regardless of the order in which those elements appear in?

Swift 3, 4 extension Array where Element: Comparable { func containsSameElements(as other: [Element]) -> Bool { return self.count == other.count && self.sorted() == other.sorted() } } // usage let a: [Int] = [1, 2, 3, 3, 3] let b: [Int] = [1, 3, 3, 3, 2] let c: [Int] = [1, 2, 2, 3, 3, … Read more

Swift 2 internal vs private

@user1007522 Could you post the entire source code for FakeViewController? You should have access to foo() from your vc variable. If you do not, I suspect something else is in play here. I found the following definitions much easier to understand (copied from UseYourLoaf – Swift 4 Access Levels) The Five Access Levels of Swift … Read more