swift3

C style for statement removed from swift 3.0, successor() is unavailable

瘦欲@ 提交于 2019-12-23 02:35:06
问题 Can anyone please help me update this for loop to swift 3.0. help appreciated. Thank you! for var index = trimmedString.startIndex; index < trimmedString.endIndex; index = index.successor().successor() { let byteString = trimmedString.substringWithRange(Range<String.Index>(start: index, end: index.successor().successor())) let num = UInt8(byteString.withCString { strtoul($0, nil, 16) }) data?.appendBytes([num] as [UInt8], length: 1) } 回答1: In Swift 3, "Collections move their index", see A New

How change font size dynamically when scrollView contentOffset y changed?

混江龙づ霸主 提交于 2019-12-23 02:32:36
问题 I have UIScrollView and UILabel . I want to change UILabel size dynamically from 33.0 to 0.0 , 0.0 to 33 when user scroll up / down my UIScrollView . How can I do this? @IBOutlet weak var myLabel : UILabel! override func viewDidLoad() { super.viewDidLoad() scrollView.delegate = self } func scrollViewDidScroll(_ scrollView: UIScrollView) { let offset = scrollView.contentOffset.y let fontpointmath = (myLabel.font.pointSize / (offset / 100) - 15) if offset > 0 { if fontpointmath < 0 { myLabel

Validate text fields swift 3

蓝咒 提交于 2019-12-23 02:19:10
问题 I am trying to make all of my text fields required to make sure that users does not leave it empty. I tried this but for some reason it's not working. I feel like my logic is correct, but it's an issue with swift's logic Here is my code: let title = txtTitle.text! let location = txtWhere.text! let when = txtWhen.text! if title != nil && location != nil && when != nil { var titleArray = [String]() var whereArray = [String]() var whenArray = [String]() let titleObject = UserDefaults.standard

Swift 3.0 closure expression: what if the variadic parameters not at the last place in the parameters list?

旧街凉风 提交于 2019-12-23 00:53:08
问题 Update at 2016.09.19 There is a tricky, indirect way to use variadic parameters before some other parameters in closure expression parameters list, haha let testClosure = { (scores: Int...) -> (_ name: String) -> String in return { name in return "Happy" } } let k = testClosure(1, 2, 3)("John") And I found some related issues in bugs.swift.org: SR-2475 SR-494 Original Post According to the document of Swift 3.0, for a closure expression, "variadic parameters can be used if you name the

Change the orientation only for specific view controllers in ios swift 2.3 and swift 3

。_饼干妹妹 提交于 2019-12-23 00:52:11
问题 I was searching that how can I change the orientation to LandScape mode only for spefic view controller when the Device Orientation is set to Portrait in the project settings . Didn't get any succesfull result. so finally I found a way to do it. this is project device orientation looks like .... In swift 2.3 add following methods override func shouldAutorotate() -> Bool { return false } override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask { return

Why does “for (index, (a, b)) in dict.enumerated()” produce an error?

南笙酒味 提交于 2019-12-22 18:44:14
问题 I tried to loop through a dictionary: let someDict = [...] for (index, (a, b)) in someDict.enumerated() { } It shows me an error: cannot express tuple conversion '(offset: Int, element: (key: String, value: String))' to '(Int, (String, String))' This is really weird. Because if we compare the required tuple: (offset: Int, element: (key: String, value: String)) with the tuple type in the for loop: (Int, (String, String)) They are compatible! Why is this happening? Note, I understand that

How to get section of UITableView from inside a child UICollectionview

拜拜、爱过 提交于 2019-12-22 18:20:12
问题 I have a UITableView with a UICollectionView within each of its rows like the illustration below. source: https://ashfurrow.com/blog/putting-a-uicollectionview-in-a-uitableviewcell-in-swift/ The intention of my app is to display a character set of a language within each table view row. Each character is contained within a collection view cell of the collectionview within the corresponding row. The problem I am having is that the english character set is being displayed for every tableview row

Making table view section expand swift

痴心易碎 提交于 2019-12-22 17:05:13
问题 I am following this tutorial for expanding and collapsing my table view section. As this demo is done in swift 2.2 I have made all the changes according to swift 3.0 . I am stuck at the below function at if condition(currentSectionCells[row]["isVisible"]) which gives me error as "Type 'NSFastEnumerationIterator.Element' (aka 'Any' has no subscript members)'". func getIndicesOfVisibleRows() { visibleRowsPerSection.removeAll() for currentSectionCells in cellDescriptors { var visibleRows = [Int]

Saving an Asset List (array) to specific CKRecord

本秂侑毒 提交于 2019-12-22 17:04:08
问题 I've a CKRecord type created in the CloudKit backend with some properties related to that class. I've String properties, Bytes and I have a Asset List property, so store some images (multiple images related to a single record). Now I'm trying so store some images and then fill the property and then trying to save it to CloudKit, but it's not working. Code goes as it follows: var images_array = [CKAsset]() // append the an image to the array images_array.append(CKAsset(fileURL: writeImage

Create SKSpriteNode with an Asset Programmatically

ぃ、小莉子 提交于 2019-12-22 13:53:50
问题 I'm attempting to programmatically create an SKSpriteNode and give it a texture that is in my Assets.xcassets folder. I figured this would be a basic procedure, but I seem to be having a lot of troubles. For a reference, here is my asset catalog with the ground asset I'm trying to set to a SKSpriteNode : Here's the code to make the sprite node: sprite.texture = SKTexture(image: UIImage(named: spriteName)!) sprite.anchorPoint = CGPoint(x: 0, y: 1) sprite.position = CGPoint(x: 0, y: 0)