swift2

How to select Swift toolchains when building with Carthage

北城以北 提交于 2019-12-19 10:08:15
问题 I am creating an iOS app and use Carthage to build external libraries. Since the libraries I use are currently both Swift 2 and Swift 3 I am in a bit of a squeeze. Thus I want to have one Swift 2 branch and one Swift 3 branch for development and then merge them when the libraries are all Swift 3 compatible. However, I am not able to select which toolchain for build for with Carthage (version 0.18). Here is the contents of my Cartfile: # Swift 2 libraries github "stephencelis/SQLite.swift" ~>

Firebase query sort order in swift?

China☆狼群 提交于 2019-12-19 09:38:31
问题 When I load the following Firebase Database data into my tableView, the data is sorted in ascending order by date. How can I order this by descending (show the newest post at the top)? Query in Xcode: let ref = self.rootRef.child("posts").queryOrderedByChild("date").observeEventType(.ChildAdded, withBlock: { (snapshot) -> Void in JSON export: "posts" : { "-KMFYKt7rmfZINetx1hF" : { "date" : "07/09/16 12:46 PM", "postedBy" : "sJUCytVIWmX7CgmrypqNai8vGBg2", "status" : "test" }, "

how to throw errors in a closure in swift?

六月ゝ 毕业季﹏ 提交于 2019-12-19 09:27:38
问题 Please look at the following code: override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? { let deleteAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "Delete", handler: { (action : UITableViewRowAction, indexPath : NSIndexPath) -> Void in if let managedObjectContext = (UIApplication.sharedApplication().delegate as! AppDelegate).managedObjectContext{ let restaurantToDelete = self

Connect to a Server with Invalid Certificate using NSURLSession (swift2,xcode7,ios9)

放肆的年华 提交于 2019-12-19 09:15:14
问题 I'm using Xcode 7, Swift 2, and iOS9. I want to connect to a web service using NSURLSession but I get the following error when I try to connect: 2015-10-13 16:07:33.595 XCTRunner[89220:4520715] NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813) 2015-10-13 16:07:33.604 XCTRunner[89220:4520571] Error with connection, details: Error Domain=NSURLErrorDomain Code=-1202 "The certificate for this server is invalid. You might be connecting to a server that is pretending to

Cannot invoke initializer for type 'sqlite3_destructor_type'

拟墨画扇 提交于 2019-12-19 09:06:52
问题 So far the answer from Martin R has worked perfectly. But starting with Swift2 it now raises the error Cannot invoke initializer for type 'sqlite3_destructor_type' with an argument list of type '(COpaquePointer)' in those lines: private let SQLITE_STATIC = sqlite3_destructor_type(COpaquePointer(bitPattern: 0)) // https://stackoverflow.com/a/26884081/1271826 private let SQLITE_TRANSIENT = sqlite3_destructor_type(COpaquePointer(bitPattern: -1)) 回答1: Taken from the github post provided courtesy

Swift 2.0 Migration errors

ε祈祈猫儿з 提交于 2019-12-19 09:03:13
问题 I've watched the WWDC sessions, reading the new programmers book on Swift, and reading all the related questions on Stack Overflow I could find. I fixed most errors in my app after migrating from Swift 1.2 to Swift 2.0. However there's still a few that I've not managed to solve. Downcasting AnyObject Error: Cannot downcast from '[AnyObject]' to a more optional type '[NSManagedObject]' Code: let fetchRequest = NSFetchRequest(entityName: formulaEntity) var error: NSError? do { let

How to get IPhone's Public IP Address without using a third party url

我是研究僧i 提交于 2019-12-19 07:22:29
问题 For my project, i need to get the IPhone's Public IP address, there are so many examples available, which show public IP address by using external / third party URL. I just want to know how to extract IPhones's IP Address without help of using another url. Note :- I used This one but shows only the local IP address , i need public IP address func getIPAddress() -> [String] { var addresses = [String]() // Get list of all interfaces on the local machine: var ifaddr : UnsafeMutablePointer

Alamofire POST request with Swift 2

流过昼夜 提交于 2019-12-19 07:11:38
问题 I am trying to make a POST request in Alamofire to return a JSON object. This code worked in Swift 1, but in swift 2 I get this invalid parameter issue: Tuple types '(NSURLRequest?, NSHTTPURLResponse?, Result<AnyObject>)' (aka '(Optional<NSURLRequest>, Optional<NSHTTPURLResponse>, Result<AnyObject>)') and '(_, _, _, _)' have a different number of elements (3 vs. 4) It seems like the error parameter was removed, but I am using the error parameter inside the function to check for errors, so how

Alamofire POST request with Swift 2

南楼画角 提交于 2019-12-19 07:11:00
问题 I am trying to make a POST request in Alamofire to return a JSON object. This code worked in Swift 1, but in swift 2 I get this invalid parameter issue: Tuple types '(NSURLRequest?, NSHTTPURLResponse?, Result<AnyObject>)' (aka '(Optional<NSURLRequest>, Optional<NSHTTPURLResponse>, Result<AnyObject>)') and '(_, _, _, _)' have a different number of elements (3 vs. 4) It seems like the error parameter was removed, but I am using the error parameter inside the function to check for errors, so how

Swift 2: Invalid conversion from throwing function of type to non-throwing function

南楼画角 提交于 2019-12-19 05:08:41
问题 I have some (ugly) self-written code ported to Swift2 and got this error message in a lambda function: What I didn't understand is, that I handle the whole code with the error throwing function JSONObjectWithData and catch the error. I throw nothing in the code. Nevertheless the compiler means that I am throwing an error. I need to understand this behavior. Please be kind because I know that I have to improve my code to make full use of the new error handling concept in swift2. Thank you very