swift2

Swift 2 iOS 9: Plist Reading and Writing

二次信任 提交于 2019-12-23 12:36:47
问题 I believe something has changed within Swift 2, because no tutorials on how to read and write to property lists seem to be working. Can anyone whose developing for iOS 9 share their method of R/W to Plists using Swift 2 on Xcode 7? 回答1: This is working for me on iOS 9 and Xcode 7: let filePath = NSBundle.mainBundle().pathForResource("FileName", ofType: "plist")! let stylesheet = NSDictionary(contentsOfFile:filePath) The only thing is that the result is NSDictionary and not Dictionary . 回答2:

UITableView cell with slider : touch not working correctly swift 2

守給你的承諾、 提交于 2019-12-23 12:36:46
问题 I m using a UITableView to display multiple custom cells, and I have one with a UiSlider, the problem is that to move the slider I need to do a long press touch to be able to move it otherwise it don't move. I tried to do a simple project with multiples slider in a UITableView and it works perfectly. So I suppose I need to configure some thing around the touch but I don't know what. Here is my code : I have this code in my view did load for gesture : override func viewDidLoad() { super

NSValue(CMTime: ) in swift 3?

旧时模样 提交于 2019-12-23 12:25:22
问题 i have this code var times = [NSValue]() for time in timePoints { times.append(NSValue(CMTime : time)) } i get an error that their is nothing called CMTime in swift 3 i can't really find any param for cm time.. 回答1: Check the reference of NSValue. init(time: CMTime) Use NSValue(time: time) . One more. If you want to convert [CMTime] to [NSValue] , you can write something like this: let times = timePoints.map(NSValue.init(time:)) 来源: https://stackoverflow.com/questions/38669061/nsvaluecmtime

Swift 2.0 replicate OBJC_ASSOCIATION_RETAIN

ぐ巨炮叔叔 提交于 2019-12-23 11:47:08
问题 I'm extending some classes in Swift 2.0 to work with ReactiveCocoa 3.0 (swift-2.0 branch), but have run into some trouble. I've followed Colin Eberhardt's tutorial, and have copy pasted some of his UIKit extension logic over to my OS X app. It all compiles fine, apart from this property: UInt(OBJC_ASSOCIATION_RETAIN) , which gives me the following compiler error. use of unresolved identifier How can I access this property? I've tried to import ObjectiveC and #import <objc/runtime.h> in the

Swift 2.0 replicate OBJC_ASSOCIATION_RETAIN

徘徊边缘 提交于 2019-12-23 11:47:01
问题 I'm extending some classes in Swift 2.0 to work with ReactiveCocoa 3.0 (swift-2.0 branch), but have run into some trouble. I've followed Colin Eberhardt's tutorial, and have copy pasted some of his UIKit extension logic over to my OS X app. It all compiles fine, apart from this property: UInt(OBJC_ASSOCIATION_RETAIN) , which gives me the following compiler error. use of unresolved identifier How can I access this property? I've tried to import ObjectiveC and #import <objc/runtime.h> in the

Why doesn't the swift compiler sometimes accept the shorthand argument name?

依然范特西╮ 提交于 2019-12-23 09:58:40
问题 The array is : var closestAnnotations:[MKAnnotation] I was wondering why the swift compiler won't accept : let closestStationAnnotations = closestAnnotations.filter({ $0.dynamicType === StationAnnotation.self }) Cannot convert value of type (_) -> Bool to expected argument type (MKAnnotation) -> Bool But accepts : let closestStationAnnotations = closestAnnotations.filter({ (annotation : MKAnnotation) -> Bool in annotation.dynamicType === StationAnnotation.self }) 回答1: I have been trying out

Swift 2 MKMapViewDelegate rendererForOverlay compiler warning

余生颓废 提交于 2019-12-23 09:32:48
问题 I am trying to draw a polyline on a map in Swift 2. It all works well, but I get a compiler warning for this code: func mapView(mapView: MKMapView!, rendererForOverlay overlay: MKOverlay!) -> MKOverlayRenderer! { if overlay is MKPolyline { let polylineRenderer = MKPolylineRenderer(overlay: overlay) polylineRenderer.strokeColor = UIColor.redColor() polylineRenderer.lineWidth = 5 return polylineRenderer } return nil } This will give me a warning says that ' Result and parameters in mapView

Swift 2: "Bool' is not convertible to 'BooleanLiteralConvertible'

烈酒焚心 提交于 2019-12-23 09:26:48
问题 I created an app in XCode 6 . Today I downloaded XCode 7 and it had updated my app to Swift 2 . There were a lot of errors, but now there is only one that I can't solve. I don't know why, but Xcode doesn't like any Bool option for animated and show this error - 'Bool' is not convertible to 'BooleanLiteralConvertible' (if you look at the function itself, you will see, that it takes exactly the Bool for animated ) var startVC = self.viewControllerAtIndex(indexImage) as ContentViewController var

Why does UIUserNotificationType.None return true in the current settings when user permission is given?

一世执手 提交于 2019-12-23 09:26:47
问题 I'm writing a method to check if the current user settings consist of certain notification types. When checking whether the current settings contain UIUserNotificationsType.None, it returns true for both when the permission was given and denied. Would anyone know why this is? func registerForAllNotificationTypes() { registerNotificationsForTypes([.Badge, .Alert, .Sound]) } func registerNotificationsForTypes(types:UIUserNotificationType) { let settings = UIUserNotificationSettings.init

protocol associated type typealias assignment compile error

做~自己de王妃 提交于 2019-12-23 09:26:38
问题 Following code: protocol SomeProtocol { typealias SomeType = Int // used typealias-assignment func someFunc(someVar: SomeType) } class SomeClass: SomeProtocol { func someFunc(someVar: SomeType) { print(someVar) } } gives compile-time error: Use of undeclared type 'SomeType' Adding, say typealias SomeType = Double , to the SomeClass resolves the error. The question is, what's the point of typealias-assignment part (which is optional btw) of protocol associated type declaration though? 回答1: In