swift2

Xcode 7 Swift 2 impossible to instantiate UIViewController subclass of generic UITableViewController

此生再无相见时 提交于 2019-12-17 14:53:15
问题 I have a generic class: class PaginatedTableViewController <GenericElement, Source: PaginationDataSource where Source.PaginatedGenericElement == GenericElement>: UITableViewController and another that I try to instantiate from storyboard: class CandidatesTableViewController: PaginatedTableViewController<Match, MatchPaginationDataSource> I can't find CandidatesTableViewController in the storyboard Custom Class dropdown menu. If I force it then cast my controller in code, app crashes at runtime

How to use both google+ and facebook login in same appdelegate.swift

旧时模样 提交于 2019-12-17 10:42:14
问题 My app use google+ signin and in my appdelegate.swift i have: func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { // Override point for customization after application launch. var configureError: NSError? GGLContext.sharedInstance().configureWithError(&configureError) assert(configureError == nil, "Error configuring Google services: \(configureError)") GIDSignIn.sharedInstance().delegate = self return true } func

UITableView Empty with iOS 9 beta 5 update

妖精的绣舞 提交于 2019-12-17 09:56:43
问题 After updating to Xcode 7 and then the iOS 9 beta 5 on my iPhone, none of my UITableViews are displaying data, except one. They are all downloading information from my Parse database, and the one that works, is downloading everything perfectly for one section of the table, but not the other. The other 3 table views download the information, and calculate the correct number of rows, however nothing is being displayed. I tried just displaying static text for all cells, however it is not even

Convert Swift Array to Dictionary with indexes [duplicate]

♀尐吖头ヾ 提交于 2019-12-17 09:48:18
问题 This question already has answers here : Error: Immutable value passed on reduce function (3 answers) Closed 4 years ago . I'm using Xcode 6.4 I have an array of UIViews and I want to convert to a Dictionary with keys "v0", "v1"... . Like so: var dict = [String:UIView]() for (index, view) in enumerate(views) { dict["v\(index)"] = view } dict //=> ["v0": <view0>, "v1": <view1> ...] This works, but I'm trying to do this in a more functional style. I guess it bothers me that I have to create the

try, try! & try? what’s the difference, and when to use each?

江枫思渺然 提交于 2019-12-17 07:58:33
问题 In Swift 2.0, Apple introduced a new way to handle errors (do-try-catch). And few days ago in Beta 6 an even newer keyword was introduced ( try? ). Also, knew that I can use try! . What's the difference between the 3 keywords, and when to use each? 回答1: Updated for Swift 5.1 Assume the following throwing function: enum ThrowableError: Error { case badError(howBad: Int) } func doSomething(everythingIsFine: Bool = false) throws -> String { if everythingIsFine { return "Everything is ok" } else

Swift 2 - Pattern matching in “if”

折月煮酒 提交于 2019-12-17 07:21:36
问题 Recently I've saw the WWDC 2015 keynote from Apple. I also looked at some documentation but I can't find a "pattern matching in if" section, how it was written on one of the slides which they have shown. (68min 00sec video from Apple Events) Do you know what's this refers to? Or the syntax? 回答1: All it really means is that if statements now support pattern matching like switch statements already have. For example, the following is now a valid way of using if/else if/else statements to "switch

How to put an image in a Realm database?

余生颓废 提交于 2019-12-17 07:13:04
问题 I'm writing an iOS application using Swift 2 and I would like to save profile picture of an account locally in a Realm database. I can't find any documentation or people talking about that. Is it possible? And how? May be is it bad to do that? 回答1: You can store images as NSData . Given you have the URL of an image, which you want to store locally, here is a code snippet how that can be achieved. class MyImageBlob { var data: NSData? } // Working Example let url = NSURL(string: "http://images

Any reason not use use a singleton “variable” in Swift?

我与影子孤独终老i 提交于 2019-12-17 06:50:57
问题 For Sept 2015, here's exactly how you make a singleton in Swift: public class Model { static let shared = Model() // ( for ocd friends ... private init() {} ) func test()->Double { return 3.33 } } then elsewhere... // file ViewController.swift, say import UIKit class ViewController:UIViewController { override func viewDidLoad() { super.viewDidLoad() print("view controller loaded!") print("singleton test! \( Model.shared.test() )") } } No problem. However. I add this little thing... public let

Synchronous URL request on Swift 2

北城余情 提交于 2019-12-17 06:48:20
问题 I have this code from here to do synchronous request of a URL on Swift 2. func send(url: String, f: (String)-> ()) { var request = NSURLRequest(URL: NSURL(string: url)!) var response: NSURLResponse? var error: NSErrorPointer = nil var data = NSURLConnection.sendSynchronousRequest(request, returningResponse: &response, error: error) var reply = NSString(data: data, encoding: NSUTF8StringEncoding) f(reply) } but the function NSURLConnection.sendSynchronousRequest(request, returningResponse:

Resolving 'Failed to call designated initializer on NSManagedObject class'

自闭症网瘾萝莉.ら 提交于 2019-12-17 04:06:13
问题 I'm new to Swift and I'm trying to learn how to use Core Data. But I'm getting this error and I'm not sure what I've done wrong. I've searched online and tried a few things but I can't get it right. Failed to call designated initializer on NSManagedObject class 'FirstCoreData.Course' When this line executes: ncvc.currentCourse = newCourse In this function: class TableViewController: UITableViewController, AddCourseViewControllerDelegate { var managedObjectContext = NSManagedObjectContext.init