swift3

NSPredicate crash after swift 3 migration

筅森魡賤 提交于 2019-12-12 03:48:26
问题 after migration to swift3, I have an issue that cannot fix let fetchRequest: NSFetchRequest<User> = User.fetchRequest() fetchRequest.predicate = NSPredicate(format: "id == %@", id) my App crashes on second line, bad access, no reason. types are right, no log, nothing, just bad access. any suggestions? Found a reason, predicate is wrong, cause id is Int64 type, have no idea what kind of predicate I need for this version of swift 回答1: The %@ format expect a Foundation object as argument,

Cant insert rows into UITableView - Swift 3

只谈情不闲聊 提交于 2019-12-12 03:48:12
问题 I have the following code which causes the app to crash with the error: *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'attempt to insert row 0 into section 0, but there are only 0 rows in section 0 after the update' I have tried multiple solutions as listed on StackOverflow but none can stop this error. Tried: "Attempt to insert row 0 into section 0, but there are only 0 rows in section 0 after the update" Error Others Code: import UIKit import

passing data between view controllers programmatically Swift

孤街醉人 提交于 2019-12-12 03:48:10
问题 I have two viewcontroller classes. MainViewController has a UITextField and SecondViewController has a UILabel. I want to print the text from the UITextField in the UILabe. Please tell me the best way to do this programmatically. Below is my code: // AppDelegate.swift import UIKit @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions:

How to resize - resample - change file size - NSImage

泪湿孤枕 提交于 2019-12-12 03:47:18
问题 I have made a lot of search on google, followed a lot of GitHub code, without success. I need to read a jpeg file, which have a DPI = 72, and size = 16000x1096 for example I need, then, to resize it, in order to save a jpeg file, with 72 DPI, 800x548 pixels this, under OSX, so I can use NSIMAGE, not UIImage ! I don't care if I lose some quality ! finally, after making som ma-ny tries, I put here my latest code, and require some help please : // get source image, jpeg, 1600x1196, 72 dpi let

UICollectionView reloadData() does not update cells in the collection view

天涯浪子 提交于 2019-12-12 03:47:06
问题 Here's high level description of what I'm trying to achieve; 1. fetch data 2. save the fetched data in an array object 3. update collection view with the size of the array Here's my code class ItemcollectionViewController:UICollectionViewController, UICollectionViewDelegateFlowLayout { let cellId = "CellId" var categories = [Category]() let viewOptionVar:ViewOptionBar = { let vOV = ViewOptionBar() vOV.translatesAutoresizingMaskIntoConstraints = false return vOV }() private func fetchData() {

How to display JSON into UILabel using UIPickerView in Swift 3.0?

别来无恙 提交于 2019-12-12 03:46:01
问题 I have these JSON output using PHP. [ {"number":"001","name":"MIKE"}, {"number":"002","name":"JOSH"} ] In Swift, I managed to select "name" value and display it into UIPickerView like below. DropdownJSON.swift import UIKit class DropdownJSON: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource, UITextFieldDelegate { @IBOutlet var dropdownTxt: UITextField! @IBOutlet var dropdownPV: UIPickerView! @IBOutlet var numberLbl: UILabel! @IBOutlet var nameLbl: UILabel! var persons = [Person]

Deprecating protocols for Swift 3 upgrade

放肆的年华 提交于 2019-12-12 03:45:36
问题 I have an iOS framework that I am upgradding to Swift 3. I would like the API's method signatures to follow the Swift 3 conventions of using a first named parameter for methods while maintaining backward compatibility. It's easy enough to add new API method signatures and deprecate the old ones. But what is the best way to handle this with protocols that are used in delegates? API for Swift 2.x: @objc(FooManager) public class FooManager { public var delegate: FooManagerDelegate? public func

Xcode storyboard is masking uitabbarcontroller elements with blue colour

假如想象 提交于 2019-12-12 03:45:34
问题 When I launched my project, all the uitabbarcontroller views are covered in blue. I didn't set the background to blue in code or by using the storyboard. And all of the elements that I add onto the storyboard go behind this mask. Here is what it looks like. What could I be doing wrong? Using Xcode 10 and Swift 3. 回答1: This is a bug in Xcode 8 , when you add an image to your tabbar item the blue area will be removed for that specific viewController . So add an image to the tabbar item and the

Saving data from Table View

限于喜欢 提交于 2019-12-12 03:45:12
问题 I have entities setup in core data where I would like to save the days that the user has selected and the time from the date picker : For e.g. I want to save Monday, Wednesday, Friday and 22:07. I can hook up the date picker to the viewcontroller to get the time. However how can I save the days that are selected ? Attempt 1 : override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { let indexPath = tableView.indexPathForSelectedRow let currentCell = tableView

Swift: collectionviewHeader delegate not working?

。_饼干妹妹 提交于 2019-12-12 03:44:52
问题 Ok, Im still new with protocols but I need to call a function (that I know works when called in the header class) from another class. To do this, In the class from which Im calling the function (its a MSMessagesAppViewController) I have: public protocol MSMessagesAppViewControllerDelegate: class { func shrinkHeight(height:CGFloat) func growHeight(height: CGFloat) } weak var delegate: MSMessagesAppViewControllerDelegate? delegate?.shrinkHeight(height: 90) Then I have in class