swift3

Periodic background synchronization

老子叫甜甜 提交于 2019-12-18 12:33:47
问题 Im quite new to iOS programming and now want to implement a periodic background synchronization to synchronize my server data with client data. What I want to achieve is comparable with Androids SyncAdapter where you can define a time interval (for example each 30 minutes) and the system will trigger the defined task automatically in the background. Until now I could not find such mechanism for Swift 3.0 so I need to ask if somone has experience or some hints for me how I can achieve this.

How to access the object of Navigation graph in SpriteKit scene editor

喜夏-厌秋 提交于 2019-12-18 12:05:52
问题 I am working with SpriteKit and draw a scene by the help of the scene editor in xcode. According to SpriteKit, we can use Navigation graph to draw the paths and I am able to draw a path using navigation graph but i am not able to access this object in swift back-end. How to access this Navigation graph object from the scene. 回答1: In the default SpriteKit template the GameViewController has a section in the viewDidLoad function that copies over the Scene Editors Entities and Graphs. class

Swift: Passing a parameter to selector

余生长醉 提交于 2019-12-18 11:57:35
问题 Using Swift 3, Xcode 8.2.1 Method: func moveToNextTextField(tag: Int) { print(tag) } The lines below compile fine, but tag has an uninitialized value: let selector = #selector(moveToNextTextField) Timer.scheduledTimer(timeInterval: 0.2, target: self, selector: selector, userInfo: nil, repeats: false) However, I need to pass a parameter. Below fails to compile: let selector = #selector(moveToNextTextField(tag: 2)) Swift Compile Error: Argument of #selector does not refer to an @objc method,

Xcode 8 beta 4: Calendar.Unit vs Calendar.Component

瘦欲@ 提交于 2019-12-18 11:19:46
问题 This Swift 3 code worked until XCode 8 beta 3: let calendar = Calendar.current let anchorComponents = calendar.components([Calendar.Unit.day, Calendar.Unit.month, Calendar.Unit.year, Calendar.Unit.hour], from: self) In Xcode 8 beta 4 Calendar.Unit appears to be renamed to Calendar.Component . Now this code let calendar = Calendar.current let anchorComponents = calendar.components([Calendar.Component.day, Calendar.Component.month, Calendar.Component.year, Calendar.Component.hour], from: self)

how to programmatically set action for barButtonItem in swift 3?

我怕爱的太早我们不能终老 提交于 2019-12-18 10:26:41
问题 Here is what I used previously, var barButtonItem = UIBarButtonItem(image: backImgs, style: UIBarButtonItemStyle.plain, target: self, action: Selector("menuButtonTapped:")) But there is some syntax changes for Swift 3. 回答1: ex:- navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Add", style: .plain, target: self, action: #selector(addTapped)) 回答2: Summarize the mostly used method in Swift 3 for adding action to a barButton. Barbutton with text navigationItem.rightBarButtonItem =

What does $0 and $1 mean in Swift Closures?

人走茶凉 提交于 2019-12-18 10:13:21
问题 let sortedNumbers = numbers.sort { $0 > $1 } print(sortedNumbers) Can anyone explain, what $0 and $1 means in swift? More Sample array.forEach { actions.append($0) } 回答1: $0 is the first parameter passed into the closure. $1 is the second parameter, etc. That closure you showed is shorthand for: let sortedNumbers = numbers.sort { (firstObject, secondObject) in return firstObject > secondObject } 回答2: It represents shorthanded arguments sent into a closure, this example breaks it down: Swift 4

Cannot conform to STPAddCardViewControllerDelegate since Xcode 8 GM on Swift 3

℡╲_俬逩灬. 提交于 2019-12-18 09:49:16
问题 Since converting my codebase to swift 3 with Xcode 8 GM, I get this error when trying to conform to the STPAddCardViewControllerDelegate (Stripe SDK). I'm very surprised by this error because even when stubbing those methods automatically with Xcode I encounter the same error. Types seem to match, no idea what's going on. extension ViewController: STPAddCardViewControllerDelegate { func addCardViewControllerDidCancel(_ addCardViewController: STPAddCardViewController) { } func

How to set label height for auto adjust in Read More/Less with Swift 3?

99封情书 提交于 2019-12-18 09:44:11
问题 I would like to create the paragraph with Read More/Read Less at the end. Here are my codes; func getLabelHeight(text: String, width: CGFloat, font: UIFont) -> CGFloat { let lbl = UILabel(frame: .zero) lbl.frame.size.width = width lbl.font = font lbl.numberOfLines = 0 lbl.text = text lbl.sizeToFit() lbl.adjustsFontSizeToFitWidth = true return lbl.frame.size.height } @IBAction func btnReadMore(_ sender: Any) { if isLabelAtMaxHeight { btnReadmore.setTitle(NSLocalizedString("Read more", comment:

Error in for loop CGFloat

旧城冷巷雨未停 提交于 2019-12-18 09:40:55
问题 I converted a project from Swift 2 to Swift 3 and now I get an error in the following line: for i:CGFloat in 0 ..< 2.0 + self.frame.size.width / ( skyTexture.size().width * 2.0 ) += 1 { which says: left side of mutating operator isn't mutable '..<' returns immutable value let skyTexture = SKTexture(imageNamed: "sky") skyTexture.filteringMode = .nearest let moveSkySprite = SKAction.moveBy(x: -skyTexture.size().width * 2.0, y: 0, duration: TimeInterval(0.1 * skyTexture.size().width * 2.0)) let

UICollection View inside Table Cell does not show images in Swift 3

这一生的挚爱 提交于 2019-12-18 09:32:12
问题 I put UICollectionView inside table cell in Home page. Each category row has their contents image. But, my problem is that when I run the app, the images under second row/second category do not show whenever I run the app. The images will show after I click more button and it will goes to details UI. Then, I click on Back button and reach the Home page. At this time, the images shows properly. I tried many codes but I don't know where it is wrong. override func viewWillLayoutSubviews() {