swift2

Swift #available keyword vs respondsToSelector

亡梦爱人 提交于 2019-12-24 05:47:19
问题 According to the pre-release Swift 2 documentation there is now an #available keyword that can be used with an if let or guard statement for checking API availability. It gives the following example: let locationManager = CLLocationManager() if #available(iOS 8.0, OSX 10.10, *) { locationManager.requestWhenInUseAuthorization() } Or let locationManager = CLLocationManager() guard #available(iOS 8.0, OSX 10.10, *) else { return } locationManager.requestWhenInUseAuthorization() Which it (the doc

Waiting for request to finish before executing the next operation

Deadly 提交于 2019-12-24 02:13:41
问题 I'm wanting to know how to wait for an operation that is sending a request to finish uploading (and get response) before executing another bit of code. I've attempted to do this with NSOperations: let testOp = BlockOperation { var result = 0 for i in 1...1000000000 { result += i } } let logOp = BlockOperation { self.debug.log(tag: "test", content: "testing") } logOp.completionBlock = { print("------- logOp completed") } logOp.addDependency(testOp) let sendOp = BlockOperation { self.debug

How do I add a scroll view to my gameScene.swift, that will scroll through a series of sprites?

夙愿已清 提交于 2019-12-24 01:27:52
问题 So I've created a 3x10 grid of sprites, that go off the bottom edge of the screen. I've added a UIScrollView, and the scroll indicators appear, but no movement actually occurs. Here's the code: import SpriteKit var buyButton = SKSpriteNode() var pic = SKTexture(imageNamed: "Button") class GameScene: SKScene, UIScrollViewDelegate { var scrollView = UIScrollView() var scrollFrame = CGRect!() override func didMoveToView(view: SKView) { /* Setup your scene here */ print(self.frame.size.width)

iOS peripheral service still empty after discovering

爱⌒轻易说出口 提交于 2019-12-24 01:15:41
问题 I am trying to use Bluetooth I have something like this : func centralManager(central: CBCentralManager, didConnectPeripheral peripheral: CBPeripheral) { Connected = true TableView.reloadData() Activityview.stopAnimating() TabBar.topItem!.rightBarButtonItem = UIBarButtonItem(title: "Suivant", style: UIBarButtonItemStyle.Done, target: nil, action: #selector(Connexion.next)) CM.stopScan() Scanning = false Refresh_Button.setTitle("Deconnecté", forState: UIControlState.Normal) let AlertMessage =

shouldAutorotate not working with navigation controllar swift 2

余生颓废 提交于 2019-12-24 00:44:04
问题 my app uses several libraryies. Bassically KYDrawerController. I want my App to use only potraite Orientation but for one ViewControllar i need both landscape and Potrait. I have search about allmost every solution on the internet. every solution was to subclass the NavigationControllar and Override ShouldAutoRotate method. but non of them worked for me. and here is the closer View of the entire StoryBoard the gray color View is the KYDrawerControllar view which is an libry uses to work as

Facebook SDK for iOS: FBSDKShareDialog is not shown

百般思念 提交于 2019-12-24 00:36:54
问题 I am a newbie in iOS, and I would like to share a link using the Facebook SDK for iOS. My code's as follows: @IBAction func shareVoucherUsingFacebook(sender: UIButton) { print("Facebook") let content : FBSDKShareLinkContent = FBSDKShareLinkContent() content.contentURL = NSURL(string: "www.google.com") content.contentTitle = "Content Title" content.contentDescription = "This is the description" let shareDialog: FBSDKShareDialog = FBSDKShareDialog() shareDialog.shareContent = content

Picking images from cache after prefetching

不羁岁月 提交于 2019-12-24 00:14:59
问题 I'm using Kingfisher framework to prefetch images. The link to the Kingfisher framework is: https://github.com/onevcat/Kingfisher Here's my code that I've written: func downloadImages() { if(self.albumImagePathArray.isEmpty == false) { //dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), { let urls = self.albumImagePathArray.map { NSURL(string: $0)! } let prefetcher = ImagePrefetcher(urls: urls, optionsInfo: nil, progressBlock: nil, completionHandler: {

iOS 9 errors and correct conversion to swift 2

我们两清 提交于 2019-12-23 22:20:10
问题 So after updating to iOS 9 and Swift 2 I had many errors in my project that even after clicking the convert automatically option didn't get fixed. Luckily most were pretty simple and I was able to figure them out but I have three major ones left. Is anyone able to help me out with these? Thanks a lot! Code chunk #1 override func layoutAttributesForElementsInRect(rect: CGRect) -> [AnyObject]? { return attributesList } Error for chunk 1 Method does not override any method from its superclass

How to dealloc UnsafeMutablePointer referenced from Swift struct

冷暖自知 提交于 2019-12-23 21:34:29
问题 If I have a Swift struct like this: struct ViewBox { let pointer: UnsafeMutablePointer<UIView> init() { pointer = UnsafeMutablePointer<UIView>.alloc(1) } } how should I ensure, that the pointer is properly deallocated, when the struct is deallocated? I can't use deinit or dealloc methods for Swift structs. Or I don't have to care and it's happening automatically? 回答1: You could wrap the pointer in a class. Something like this: struct ViewBox { class WrappedPointer() { let pointer:

Cannot subscript a value of type [String: AnyObject]? with an index of type String

混江龙づ霸主 提交于 2019-12-23 21:05:44
问题 I know have many the same question but still cannot find the way to fix my error. Please see the image for more detail. I used Xcode 7 and swift 2.0 Edit: fcking the warning of Swift. finnaly (change?[NSKeyValueChangeNewKey]?.boolValue)! fixed the error 回答1: change is an optional. Either unwrap the optional let isCaptureStillImage = change![NSKeyValueChangeNewKey]!.boolValue or use optional bindings if let changeNewKey = change?[NSKeyValueChangeNewKey] { let isCaptureStillImage = changeNewKey