swift3

Swift 3 passing var through a series of Segues / ViewControllers

拥有回忆 提交于 2019-12-25 09:27:13
问题 I am having an unexpected problem passing var's through Segue to a VC. Worked fine in Objective C and early version of Swift. Here is what I am doing: I'm extracting a set of variables from a downloaded json file to populate a TableViewCell, then to pass the Cell displayed variables plus the other vars relating to that Cell selection to a DetailViewController. This is through prepare for Segue, setting up vars on the DetialViewController. Then destination.myVarToSend = myVar ..... That all

Background location update every n minutes

梦想的初衷 提交于 2019-12-25 09:26:32
问题 I'm writing an application that requires location updates every n minutes and sends data to a server even when the application is in background mode. I have gone through so many links about this task. As I found the proper solution is to use a timer and make it as a background task. Concerning to this I have two questions: How can I implement these regular background location updates? I understand that Apple allows background tasks for an only certain time. So how can I make long-running

How to add two UITextViews into a UIView?

ぐ巨炮叔叔 提交于 2019-12-25 09:26:30
问题 I want to add two UITextViews into a UIView which is placed in a UIStackView . It works if I set width and height of the UITextViews . The problem is I do not know how to place them equally inside the UIView without setting width and height. The result should be like this: class PanelCell: UICollectionViewCell { let currentRunView: UIView = { let view = UIView() view.layer.cornerRadius = 5.0; view.layer.masksToBounds = true; view.backgroundColor = UIColor(hex: 0x1A1A1A) return view }() let

Call Objective-C function in Swift 3

微笑、不失礼 提交于 2019-12-25 09:19:25
问题 I am embeding JBParallaxCell , a UITableViewCell subclass. I want to call a function: - (void)scrollViewDidScroll:(UIScrollView *)scrollView { // Get visible cells on table view. NSArray *visibleCells = [self.tableView visibleCells]; for (JBParallaxCell *cell in visibleCells) { [cell cellOnTableView:self.tableView didScrollOnView:self.view]; } } I converted this code to Swift: func scrollViewDidScroll(_ scrollView: UIScrollView) { let visibleCells = table.visibleCells var cells :

The data could not be read because it isn't in the correct format JSON & SWIFT 3

喜欢而已 提交于 2019-12-25 09:17:05
问题 Here is Stripe's example code for retrieving a customer (https://github.com/stripe/stripe-ios/blob/master/Example/Stripe%20iOS%20Example%20(Simple)/MyAPIClient.swift): @objc func retrieveCustomer(_ completion: @escaping STPCustomerCompletionBlock) { guard let key = Stripe.defaultPublishableKey() , !key.contains("#") else { let error = NSError(domain: StripeDomain, code: 50, userInfo: [ NSLocalizedDescriptionKey: "Please set stripePublishableKey to your account's test publishable key in

.Map producing [T] in Swift 3 after Converting from Swift 2

做~自己de王妃 提交于 2019-12-25 09:17:04
问题 I just converted a project from Swift 2 to Swift 3 and am getting an error, but I do not understand why the code is a problem: var imagesInProject : NSArray? func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. let paths = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask

Swift 3.0 - How to build Sourcekit and Sourcekitten in Ubuntu 14.04?

天大地大妈咪最大 提交于 2019-12-25 09:14:42
问题 What are the steps in building Sourcekit and Sourcekitten for the stable release version of Swift 3.0? Thanks in advance. Note: Dependencies and other tools for building are already installed as per https://github.com/apple/swift 回答1: This is duplicate to Building Swift SourceKit on Linux Updated Nov.24, 2016. Build Sourcekit The official branch of swift may still have the issue https://bugs.swift.org/browse/SR-1676. But Norio Nomura maintained a docker building environment here https:/

Swift 3 - CFHostScheduleWithRunLoop crash

时间秒杀一切 提交于 2019-12-25 09:10:09
问题 I am doing a reverse DNS in Swift, my previous code on Swift 2.2 was working fine, also I have implemented it in Objective-C and it works to. However I am not able to make it works in Swift 3.0 Swift 2.2 //: Let's set up the `sockaddr_in` C structure using the initializer. var sin = sockaddr_in( sin_len: UInt8(sizeof(sockaddr_in)), sin_family: sa_family_t(AF_INET), sin_port: in_port_t(0), sin_addr: in_addr(s_addr: inet_addr(ip)), sin_zero: (0,0,0,0,0,0,0,0) ) //: Now convert the structure

Swift 3.0: compiler error when calling global func min<T>(T,T) in Array or Dictionary extension

风格不统一 提交于 2019-12-25 09:09:42
问题 After converting from Swift 2.2 to 3.0 my Array extension does not compile anymore, because it contains a call to global standard library function min<T>(T,T) and shows compiler error extra argument in call . Here's a simple way to reproduce the error: extension Array { func smallestInt(first: Int, second: Int) -> Int { return min(first, second) // compiler error: "Extra argument in call" } } I get the same error when adding the same function to an extension of Dictionary , while the exact

Replace characters in List of strings

孤者浪人 提交于 2019-12-25 09:06:13
问题 I've sorted my list with objects by propertie time which is String not date . The sample output before sorting : 07:05:10 AM 07:05:01 AM 07:04:49 AM 07:04:44 AM 06:53:58 AM 06:53:47 AM 01:03:21 AM 12:03:21 AM and after invoking instrudtion : self.myList = self.myList.sorted { $0.mytime < $1.mytime } going to looks like this : 01:03:21 AM 06:53:47 AM 06:53:58 AM 07:04:44 AM 07:04:49 AM 07:05:01 AM 07:05:10 AM 12:03:21 AM Could I replace 12:03:21 AM to 00:03:21 AM only when it is AM and 12 at