swift2

Rounded rect using UIRectCorner in Swift not working

↘锁芯ラ 提交于 2019-12-18 09:31:01
问题 I am trying to create a rounded rect for the UITableViewCell I have created in a storyboard. I am using Swift 2 in Xcode 7. I have two views in the prototype cell, topView and Bottom view. I want the topView to have its top corners rounds, and the bottomView to have its corners rounded. in awakeFromNib (may go somewhere else better later): ... self.topView.backgroundColor = UIColor.redColor() self.bottomView.backgroundColor = UIColor.grayColor() self.setMaskToView(self.topView, corners

Is it possible for Swift to inherit from an lightweight generic Objective-c Class?

若如初见. 提交于 2019-12-18 09:19:02
问题 I have two classes, the base class is in Obj-c and the subclass is in Swift. The Obj-c class uses new XCode 7's lightweight generic feature defined as follows: @interface BaseController<T: SFObject *> : UIViewController @property(nonatomic, strong) T model; @end That works fine for Obj-c subclasses. Now for Swift if I define the generic type as I usually do I get the following error: Cannot specialize non-generic type 'BaseObjcController'. My second class is defined as follows: class

UIApplication.sharedApplication() is unavailable

[亡魂溺海] 提交于 2019-12-18 07:36:42
问题 I just upgraded from XCode 6.4 to Xcode 7 GM and get started to change the code to be compliant with Swift 2. I could not come over the following errors. The project is a keyboard extension and the snippet is from the containing app. let s = "https://itunes.apple.com/" UIApplication.sharedApplication().openURL(NSURL(string : s)!) Error 1: 'sharedApplication()' is unavailable: Use view controller based solutions where appropriate instead. Error 2: 'openURL' is unavailable. This might be

Swift 2 to 3 Migration dispatch_get_global_queue [duplicate]

五迷三道 提交于 2019-12-18 07:23:56
问题 This question already has answers here : How do I dispatch_sync, dispatch_async, dispatch_after, etc in Swift 3, Swift 4, and beyond? (6 answers) Closed 3 years ago . I have the following code that I've been trying to translate into swift 3 from swift 2. Here is what I have so far. DispatchQueue.async(group: DispatchQueue.global(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),execute: { self.controllerDelegate?.codeToRun(progressWindowViewController: self) }) I am getting an error that says Cannot invoke

How to increase (animate) the width of the square on both ends?

空扰寡人 提交于 2019-12-18 05:49:07
问题 I have created a square that is 40x40, as shown above. I have a 4x40 strip that I'd like to use to animate (increase) the width of my square till it takes the the width of the whole screen within a second, regardless of the square's position. Quite similar to that of a progress bar loading on both sides. UPDATE I forgot to mention that the square is a physics body, hence the physics body must also increase as the sprite increases. 回答1: What you want to do is use SKAction.scaleXTo to achieve

swift 2.0 keychain type errors for SecItemCopyMatching

瘦欲@ 提交于 2019-12-18 04:13:11
问题 We had this snippet of code with the previous version of Swift var retrievedData: NSData? var extractedData: Unmanaged<AnyObject>? = nil let status = SecItemCopyMatching(keyChainQuery, &extractedData) if (status == errSecSuccess) { if let validExtractedData = extractedData { let opaque = validExtractedData.toOpaque() retrievedData = Unmanaged<NSData>.fromOpaque(opaque).takeUnretainedValue() } } However this now gives us the following error: Cannot convert value of type 'inout Unmanaged?' (aka

Swift setting Badge Value for UITabBarItem

∥☆過路亽.° 提交于 2019-12-18 03:02:23
问题 I'm attempting to add a badge alert label like the one in the screenshot attached. I've tried to search for titles, labels uitabbar items but I'm stuck. Any suggestion is appreciated. 回答1: Xcode 7.2.1 Swift 2.1.1 You just have to set the badgeValue for your desired UITabBarItem as follow: tabBarController?.tabBar.items?[4].badgeValue = "1" // this will add "1" badge to your fifth tab bar item // or like this to apply it to your first tab tabBarController?.tabBar.items?.first?.badgeValue =

Swift 2.0: Could not cast value MyApp.MyCustomClass to MyAppTests.MyCustomClass when using Set

谁都会走 提交于 2019-12-18 03:02:05
问题 This is an error: Could not cast value of type MyApp.Member (0x1674daf8) to MyAppTests.Member (0x4c07248). You can reproduce a bug in easy way: Setup two NSManagedObject @objc(Member) class Member: NSManagedObject { @NSManaged var family: Family } @objc(Family) class Family: NSManagedObject { @NSManaged var members: Set<Member> } Setup this also in your .xcdatamodel : Then in your TestFile : func testA() { let family = Family.MR_createEntityInContext(context) let father = Member.MR

How to transfer a UIImage using Watch Connectivity

ε祈祈猫儿з 提交于 2019-12-18 02:49:11
问题 How can I transfer an UIImage over WatchConnecitivity from the iPhone to the Apple Watch with no user interaction on the phone, and only loads because the watch calls for it programmatically. I need this because the image processing to create the UIImage uses logic unavailable in the Watchkit API, so it must be created from the phone. I have seem some examples of Watch Connectivity using: func startSession() { session?.delegate = self session?.activateSession() } However, I am new to watch

When to use inout parameters?

早过忘川 提交于 2019-12-17 22:33:39
问题 When passing a class or primitive type into a function, any change made in the function to the parameter will be reflected outside of the class. This is basically the same thing an inout parameter is supposed to do. What is a good use case for an inout parameter? 回答1: inout means that modifying the local variable will also modify the passed-in parameters. Without it, the passed-in parameters will remain the same value. Trying to think of reference type when you are using inout and value type