swift2.1

Nested Closures in Swift 2.1

别说谁变了你拦得住时间么 提交于 2020-01-01 14:36:58
问题 I want to clear about Nested Closures in Swift 2.1 Here I declare a nested closure, typealias nestedDownload = (FirstItem: String!)-> (SencondItem: String!)->Void Then I use this nestedDownload closure as a parameter of the following function and try to complete the compliletion parameter value in function like as func nestedDownloadCheck(compliletion:nestedDownload){ compliletion(FirstItem: "firstItem") } But this says the error, " Expression resolves to an unused function " Also , when I

Nested Closures in Swift 2.1

核能气质少年 提交于 2020-01-01 14:36:50
问题 I want to clear about Nested Closures in Swift 2.1 Here I declare a nested closure, typealias nestedDownload = (FirstItem: String!)-> (SencondItem: String!)->Void Then I use this nestedDownload closure as a parameter of the following function and try to complete the compliletion parameter value in function like as func nestedDownloadCheck(compliletion:nestedDownload){ compliletion(FirstItem: "firstItem") } But this says the error, " Expression resolves to an unused function " Also , when I

Nested Closures in Swift 2.1

拈花ヽ惹草 提交于 2020-01-01 14:36:13
问题 I want to clear about Nested Closures in Swift 2.1 Here I declare a nested closure, typealias nestedDownload = (FirstItem: String!)-> (SencondItem: String!)->Void Then I use this nestedDownload closure as a parameter of the following function and try to complete the compliletion parameter value in function like as func nestedDownloadCheck(compliletion:nestedDownload){ compliletion(FirstItem: "firstItem") } But this says the error, " Expression resolves to an unused function " Also , when I

Custom Font in IOS Not Reflected On Device

安稳与你 提交于 2019-12-31 02:08:26
问题 i followed this tutorial and the custom font was shown on my storyboard but when i executed my app (on simulator or device) the font is not reflected. can anyone help. this is what i did: 1- downloaded a .ttf file and copied it to my project 2- added "Fonts Provided By Application" in info.plist and added a row having the name of my custom font. 3- opened storyboard and selected the UILabel i want to have a custom font for, and selected the font as custom then selected my font. the font was

UITextView change text color of specific text

試著忘記壹切 提交于 2019-12-29 07:14:24
问题 I want to change the text color of a specific text within a UITextView which matches an index of an array. I was able to slightly modify this answer but unfortunatly the text color of each matching phrase is only changed once. var chordsArray = ["Cmaj", "Bbmaj7"] func getColoredText(textView: UITextView) -> NSMutableAttributedString { let text = textView.text let string:NSMutableAttributedString = NSMutableAttributedString(string: text) let words:[String] = text.componentsSeparatedByString("

NSUrlSession Running Slow in Swift

五迷三道 提交于 2019-12-25 03:39:14
问题 In swift I am downloading data in swift to my iOS app. It works just fine although what ends up happening is it can take up to 20 seconds for it to load even though I am on a fast connection. I don't understand why this happens. I was almost thinking about downloading all the data before the app opens although I don't want to do that because I know it is possible to speed it up which I know is possible because apps like YouTube and Facebook can load and refresh in less than 20 seconds. Heck,

Generic LazyCollection type

送分小仙女□ 提交于 2019-12-24 14:01:04
问题 I need a function that returns a lazy generator of various composed generator functions such as filter and map. For example, if I want to apply lazy.filter().map() the code looks like: // Simplified typealias MyComplexType = Int typealias MyComplexCollection = [MyComplexType] func selection() -> LazyMapCollection<LazyFilterCollection<MyComplexCollection>, Int> { let objects:MyComplexCollection = [1, 2, 3, 4, 5, 6] let result = objects.lazy.filter({$0 < 4}).map({$0 * 10}) return result } for

Down casting multiple protocol Array<protocol<P1, P2>> to Array<P1>

a 夏天 提交于 2019-12-23 16:32:59
问题 So I have two arrays var arrayOne:Array<protocol<P1,P2>> var arrayTwo:Array<P1> Where P1 and P2 are protocols. Question is how to make downcasting operation arrayTwo = arrayOne as Array<P1> What i get from Xcode is: Cannot convert value of type 'Array<protocol<P1, P2>>' to specified type 'Array<P1>' 回答1: You need to cast the elements of the array, not the array itself. arrayTwo = arrayOne.map { $0 as P1 } Or as MartinR stated, there is even no need to cast the element. arrayTwo = arrayOne.map

Delegate using Container View in Swift

时光怂恿深爱的人放手 提交于 2019-12-20 12:35:50
问题 I'm developing an app for iPad Pro. In this app, containerView use to add additional views and interact with them. First, I created a protocol: protocol DataViewDelegate { func setTouch(touch: Bool) } Then, I created my first view controller import UIKit class ViewController: UIViewController, DataViewDelegate { @IBOutlet var container: UIView! @IBOutlet var labelText: UILabel! override func viewDidLoad() { super.viewDidLoad() } func setTouch(touch: Bool) { if touch == true { labelText.text =

Display data in two different TableView in the same View in Swift

半世苍凉 提交于 2019-12-20 06:32:50
问题 I'm creating an app for iPad, and because of their size decided to do something a little different. I'm creating something like this: I am using two UITableView in a UIView. I need to display data 'product categories' in the first TableView and 'products' in the second TableView. The problem is display data in two tables with direferentes contents. Another detail: When a category is selected, the table 'product' is recharged with other data of other products. My question is: How can I display