swift2

Re open the review and converter to Swift 2.0-Xcode 7

我的未来我决定 提交于 2020-01-06 03:09:18
问题 I open my project (swift 1.2) by Xcode 7, and the Xcode suggestion to me convert to Swift 2.0. But I canceled it, now I want to open the review and converter of Xcode 7. How to do that? 回答1: This is the answer you are looking for To Latest Swift Syntax at the latest menu. 来源: https://stackoverflow.com/questions/32692935/re-open-the-review-and-converter-to-swift-2-0-xcode-7

App crash when cable disconnected from Mac

你离开我真会死。 提交于 2020-01-06 02:42:08
问题 this app is running normally on simulator, is running normally while attached in my Mac, but when disconnected it crashes. There are other very old posts in StackOverflow, but even that I tried to follow did not work as well. What I did till now was: 1-To stop Xcode first and after disconnect the cable does not work. 2-To Stop the app first and after disconnect the iPhone does not work, the app does not run in the iPhone 3-Delete the app from the iPhone and run it again 4-Product Clean in

Creating Range<String.Index> from constant Ints

ぃ、小莉子 提交于 2020-01-06 02:27:24
问题 What is wrong with this piece of code for constructing a range that should then serve in a call to substringWithRange ? let range = Range<String.Index>(start: 0, end: 3) The Swift compiler (in Xcode 7.1.1) marks it with this error message: Cannot invoke initializer for type 'Range<Index>' with an argument list of type '(start: Int, end: Int)' 回答1: You need to reference the startIndex of a specific string, then advance: let longString = "Supercalifragilistic" let startIndex = longString

Long delay when pushing a view controller from GCD

本秂侑毒 提交于 2020-01-05 04:07:38
问题 The issue is now resolved. See the last edit for details! I have an UIViewController with an audio visualisation and a button. When a button is pressed, the following function is fired: func use(sender:UIButton!) { // Analyse the audio let analysisQueue = dispatch_queue_create("analysis", DISPATCH_QUEUE_CONCURRENT) dispatch_async(analysisQueue, { // Initialise the analysis controller let analysisController = AnalysisController() analysisController.analyseAudio(global_result.filePath,

Why do classes need to be “final” when adopting a protocol with a property with type “Self”?

北战南征 提交于 2020-01-05 04:04:05
问题 I can use generic protocols just fine, but am trying to grasp the reasoning behind some limitations of generic protocols. Example: internal protocol ArchEnemyable { var archEnemy: Self? { get } } internal final class Humanoid: ArchEnemyable { internal var archEnemy: Humanoid? // is the adoption to Self, works only when class is final internal init(otherOne pOtherOne: Humanoid?) { self.archEnemy = pOtherOne } } I do not find any example where it would not work, when it is not final. Do one of

Swift Casting Generic to Optional with a nil value causes fatalError

♀尐吖头ヾ 提交于 2020-01-05 02:58:10
问题 Using Swift 2, in my contrived example I am converting a String to an Int or more specifically an Int or an Int? using a generic. In the case where the Int? should be nil the cast will fail with a fatalError: fatal error: unexpectedly found nil while unwrapping an Optional value These look like they may be similar/duplicate questions: Swift - casting a nil core data string as an optional value Swift: detecting an unexpected nil value in a non-optional at runtime: casting as optional fails My

Adopting Equatable Protocol for Enum with nested Enum values

混江龙づ霸主 提交于 2020-01-04 05:36:12
问题 Assuming we have this datastructure: enum Vehicle: Equatable { enum Car { case BMW(Int) case Audi(Int) } enum Bike { case Ducatti(Int) case Honda(Int) } } that represents various vehicles with their horsepower as their associated value. I am trying to conform to the Equatable protocol in order to be able to perform Vehicle equivalence with no success. I am trying with: func ==(a: Vehicle, b: Vehicle) -> Bool { switch(a, b) { case(let Car.BMW(hp1), let Car.BMW(hp2)): return hp1 == hp2 default:

Window title bar appears transparent issue (Not really transparent)

依然范特西╮ 提交于 2020-01-04 04:00:31
问题 I am trying to make my app have more 'flat' feel so I think it is a good idea to hide the title bar. However, in reality titlebarAppearsTransparent seems only remove the title bar shadow but not make the title bar truly transparent. Before using any code to modify the title bar, After adding the following code (starting have a better feel), self.window?.titlebarAppearsTransparent = true Setting the background color to white, self.window?.backgroundColor = NSColor.whiteColor() self.window?

com.apple.product-type.bundle.ui-testing, but there's no such product type for the 'iphonesimulator' platform

本秂侑毒 提交于 2020-01-04 02:41:06
问题 I used Xcode 7 Beta to develop this project and now I switch to Xcode 6.4 So I had this issue now and i have tried clean, but it doesn't work target specifies product type 'com.apple.product-type.bundle.ui-testing', but there's no such product type for the 'iphonesimulator' platform 回答1: If you are not using UI Testing, you can delete the UITest target in your project's build settings. 来源: https://stackoverflow.com/questions/31914765/com-apple-product-type-bundle-ui-testing-but-theres-no-such

Cannot convert [Int] to [Int] in generic implementation

老子叫甜甜 提交于 2020-01-03 18:31:31
问题 Trying to create a generic data source I bumped into this error and I was wondering why this isn't compilable. The error: Cannot convert return expression of type '[Int]' to return type '[Int]' The code: protocol DataSource { func getData<T> () -> [T] } class IntDataSource<Int>: DataSource { let data:[Int] = [] func getData<Int>() -> [Int] { return data } } The error is thrown on the return statement in IntDataSource. I know this could be done in better ways with typealias DataType var data: