swift2

SWIFT 2 - Sort Multi dimensional array by date

戏子无情 提交于 2019-12-25 03:34:56
问题 I am trying to sort my array by date, I have been trying almost everything but with no results. This is the closer I got but I get a waring: Constant 'sortedDate' inferred to have type () var Names = [[String]]() Names = [ ["aaa", "bob", "ccc", "26-10-2015 17:50"], ["aaa-1", "bbb-1", "ccc-1", "22-10-2015 11:20"], ["aaa-2", "bbb-2", "bbb-2", "01-03-2015 17:00"] ] let sortedDate = Names.sortInPlace({ return $0[3].compare($1[3]) == NSComparisonResult.OrderedAscending }) print("\(sortedDate)")

Faults - core data can only acces object once when working with UITableView

独自空忆成欢 提交于 2019-12-25 03:34:53
问题 Ok, this is a weird bug I just can't figure out. I fetch expenses from a core data entity. Then I sort those results on the date. I use this sorted structure to get the correct data for the correct section and row in the tableView. This code all works and the cells in the TableView outlets are filled in correctly in cellForRowAtIndexPath. But when a cell goes out of the tableView (=queued) and later gets loaded in back again(=Dequeued), I can't access the expense and its relationship anymore.

Add iPhone X layout support to old Xcode 7 / Swift 2 project

和自甴很熟 提交于 2019-12-25 01:34:07
问题 What I have? An old project using Swift 2 and building/running without any issue on Xcode 7. It has a lot of dependencies and sophisticated architecture which makes it complicated to migrate to swift 3/4 (in a short period of time). When app is running on iPhone X it has black bars on top and bottom of the sreen (sizing like on iPhone 6/7/8) What I need? I need to make the app running on iPhone X without black bars on top and bottom of the screen (fullscreen) without updating whole project .

Swift error handling - determining the error type

血红的双手。 提交于 2019-12-24 18:23:15
问题 In Swift error handling - how do you know what error type is being thrown without looking at the implementation and how do you handle the case where ErrorType-derived error and NSError can be thrown by the method? e.g. Code does not show what type of error will be thrown. public func decode(jwt: String) throws -> JWT { return try DecodedJWT(jwt: jwt) } 回答1: You can catch the thrown error to a variable and do runtime analysis of the variable. E.g., for some unknown implementation: /* ---------

Custom UiCollectionViewCell class init not being called

回眸只為那壹抹淺笑 提交于 2019-12-24 16:30:10
问题 Hi I'm using this code to try and make the text resize though I can't seen to get the label to resize. Also the init method in the custom class is not being called. Here is my code: class Cell: UICollectionViewCell { @IBOutlet weak var label: UILabel! override init(frame: CGRect) { super.init(frame: frame) print("init—>Not being called???\n") self.label.adjustsFontSizeToFitWidth = true self.cell.label.sizeToFit() } required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) } } What

Swift strange '==' behavior with Dictionary

独自空忆成欢 提交于 2019-12-24 16:07:38
问题 In Swift 2.1, following code can be compiled. let a = [1: [1]] a == [1: [1]] However, following code cannot be compiled. let a = [1: [1]] let b = [1: [1]] a == b // => binary operator '==' cannot be applied to two '[Int : Array<Int>]' operands How understand this behavior? 回答1: There is a == operator comparing two Swift dictionaries, however it requires that the value type is Equatable : public func ==<Key : Equatable, Value : Equatable>(lhs: [Key : Value], rhs: [Key : Value]) -> Bool The

Posting image with Swift 2 + AFNetworking

99封情书 提交于 2019-12-24 16:04:51
问题 I have the following code let manager = AFHTTPRequestOperationManager() manager.POST( "http://shipeala.redmintlabs.com/api/orders/create", parameters: params, constructingBodyWithBlock: { (formData : AFMultipartFormData!) -> Void in formData.appendPartWithFileData(SHOrderImage.getInstance().image!, name: "photo", fileName: "image.jpg", mimeType: "image/*") }, success: { (operation: AFHTTPRequestOperation!, "" }, failure: { (operation: AFHTTPRequestOperation!, error: NSError!) -> Void in "" }

How come I can't successfully load an NSImage from it's full path? Swift 2

情到浓时终转凉″ 提交于 2019-12-24 16:04:41
问题 I'm trying to load an image from an absolute path into an NSImage and even though the same full path works in other scenarios when I'm using it in this context, the variable just ends up being nil . I've tried using both the file path and an NSURL to achieve it. //: Playground - noun: a place where people can play import Cocoa import AppKit print ("Starting") /** Attempt to do via NSURL **/ // The workspace var workspace = NSWorkspace.sharedWorkspace() // Main screen var screen = NSScreen

cellForNextPageAtIndexPath not visible in swift2

丶灬走出姿态 提交于 2019-12-24 15:03:47
问题 I am implementing PFQueryTableViewController from Parse with sections and pagination. Because I am using sections, I need to set the 'load more' cell on my own. However, It seems that I can't access the method cellForNextPageAtIndexPath - I get an error: ''UITablView' does not have a member name 'cellForNextPageAtIndexPath' ' . I've looked around and the only resource on the subject seems to be this unanswered question: cellForNextPageAtIndexPath in swift Here's my code: override func

How to have 10 characters total and make sure at least one character from 4 different sets is used randomly

帅比萌擦擦* 提交于 2019-12-24 14:32:53
问题 I have a text field and a button that generates a random set of characters. Set 1 = lowercase, set 2 = uppercase, set 3 = numbers, set 4 = symbols I want the the button to generate no more no less that 10 characters and minimum pull from each of the sets at least once. My idea of how to do it so far is let roomIDGenerated = uniqueRoomID.text let roomIDCount = roomIDGenerated?.characters.count let randomCharacterSet = arc4random() upp while roomIDCount < 10 { <#code#> } But I don't see how to