swift3

“targetContentOffset” UICollectionViewFlowLayout not working properly

会有一股神秘感。 提交于 2019-12-24 01:33:26
问题 I have a requirement to keep UICollectionViewCell center aligned in portrait mode. Final result should be like : animation I'm using this code to do this: override public func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint, withScrollingVelocity velocity: CGPoint) -> CGPoint { var layoutAttributes: Array = layoutAttributesForElements(in: collectionView!.bounds)! if layoutAttributes.count == 0 { return proposedContentOffset } var firstAttribute:

Swift: Tableview scrolls under navigation bar but over status bar?

≡放荡痞女 提交于 2019-12-24 01:15:50
问题 I hid the navigation bar's shadow using the following trick: self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default) self.navigationController?.navigationBar.shadowImage = UIImage() I also have the following set: self.extendedLayoutIncludesOpaqueBars = true self.automaticallyAdjustsScrollViewInsets = true self.tabBarController?.tabBar.isHidden = true Everything looks fine on my page, except that when I scroll up my tableView it goes under the navigation bar as

Can't get didSelectRowAt to work for TableView

☆樱花仙子☆ 提交于 2019-12-24 01:12:41
问题 I am having trouble getting the didSelectRowAt method to work for a TableView inside of a regular ViewController . I have already made sure that the delegate and data source for the table are set in the ViewController code. This ViewController populates the tableview cells with results from a search query to an API , and the rendering of cell data is working fine. It's just the didSelectRowAt method that is not registering. I did try manually adding the same delegate information on the Main

Lots of errors when trying to use AWS DynamoDB with Swift 3

穿精又带淫゛_ 提交于 2019-12-24 00:43:39
问题 I'm new to swift development and am trying to incorporate a backend. I figured AWS would be a good way to accomplish what I want to get done. I'm currently just trying to get the sample project file that they create for you working, and it has so many errors it's incredible. What I've realized is that AWS creates the files in Swift 2, and so running them in Swift 3 is quite hard. I converted the code to Swift 3 when I opened it in xCode and have made maybe 30 changes to lines after that, just

Alamofire error after Swift 3.0 migration: “Extra argument in Call'” (request method)

↘锁芯ラ 提交于 2019-12-24 00:42:26
问题 I am currently in the process of updating my codebase to Swift 3.0, and I am using Alamofire. Thus, I had to update Alamofire to 4.0 (Alamofire git repo). I have a request method to fetch data from the server, and before migration, it worked wonderfully. After using Xcode's migration tool, I ended up with this error : "Extra argument in Call" . I'm not quite sure why this method is no longer working. Any help would be wonderful! class func makeRequest( _ method: RequestMethod, authorization:

How to send multiple buttons in button.addTarget action? Swift3

早过忘川 提交于 2019-12-24 00:32:45
问题 How can I send button and button2 into my pressButton2 function? I need to change color of button and button2 when user will touch button2... When my button2.addTarget looks like this, I got an error: 'Expected expression in list of expressions'. import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. let button = UIButton(frame: CGRect(x: 10, y: 50, width: 100, height: 100

UIButton is not clickable after first click

我的未来我决定 提交于 2019-12-24 00:12:34
问题 I am trying to bring a subview from bottom when button is clicked. But only for the first time the button is clickable. For second click after animation button is not clickable. Here is the code. class AnimateView: UIView { var button: UIButton! var menuView: UIView! var mainView: UIView! override init(frame: CGRect) { super.init(frame: frame) mainView = UIView(frame: CGRect(x: 0, y: 0, width: self.frame.size.width, height: self.frame.size.height)) mainView.clipsToBounds = true mainView

What's Swift's “fromAfter” call in array slices?

╄→гoц情女王★ 提交于 2019-12-23 23:17:28
问题 Swift 3 has upTo and through which are noninclusive, inclusive respectively func prefix(upTo: Int) Returns a subsequence from the start of the collection up to, but not including , the specified position. . func prefix(through: Int) Returns a subsequence from the start of the collection through the specified position. for the other end it has from func suffix(from: Int) Returns a subsequence from the specified position to the end of the collection. which seems to be inclusive What's the non

Swift 3 Migration - Double Extension rounding issue

不打扰是莪最后的温柔 提交于 2019-12-23 22:12:09
问题 I'm migrating our codebase to Swift 3 and I've come across a compilation issue that I can't explain or fix. I have a method in a Double extension that rounds the Double to a certain number of digits: public func roundToPlaces(places: Int) -> Double { let divisor = pow(10.0, Double(places)) return round(self * divisor) / divisor } For example: 12.34567.roundToPlaces(2) should return 12.35 . However, I'm getting a compilation issue for the round method used in this extension. It's saying that I

Are setting and reading a Bool atomic operations in Swift?

陌路散爱 提交于 2019-12-23 20:46:27
问题 Simple as the title states. Basically, in this example, could we ever get an invalid state: var myBool = false // Thread 1 while true { if randomEvent() { myBool = true } } // Thread 2 while true { if myBool { print("Was set to true") } else { print("Not set") } } Could this ever crash because myBool is in some invalid state? Or is this "safe"? 回答1: I'm not sure what you think this has to do with "thread-safe" or "atomic" or even Swift. The nature of multithreading is as follows. Whenever you