swift3

UICollectionView Layout like SnapChat?

只愿长相守 提交于 2019-12-17 04:38:13
问题 how do we create a UICollectionViewLayout like the SnapChat's stories? Any ideas please? I'd like to have a solution without external library. 回答1: Based on a precedent answer adapted to your issue: -(id)initWithSize:(CGSize)size { self = [super init]; if (self) { _unitSize = CGSizeMake(size.width/2,80); _cellLayouts = [[NSMutableDictionary alloc] init]; } return self; } -(void)prepareLayout { for (NSInteger aSection = 0; aSection < [[self collectionView] numberOfSections]; aSection++) { /

UICollectionView Layout like SnapChat?

心已入冬 提交于 2019-12-17 04:38:00
问题 how do we create a UICollectionViewLayout like the SnapChat's stories? Any ideas please? I'd like to have a solution without external library. 回答1: Based on a precedent answer adapted to your issue: -(id)initWithSize:(CGSize)size { self = [super init]; if (self) { _unitSize = CGSizeMake(size.width/2,80); _cellLayouts = [[NSMutableDictionary alloc] init]; } return self; } -(void)prepareLayout { for (NSInteger aSection = 0; aSection < [[self collectionView] numberOfSections]; aSection++) { /

How to create managedObjectContext using Swift 3 in Xcode 8?

强颜欢笑 提交于 2019-12-17 04:22:56
问题 Facing issue "Value of type 'AppDelegate' has no member 'managedObjectContext' In new Xcode 8 (using Swift 3, iOS 10) when trying to create new context in View Controller let context = (UIApplication.shared().delegate as! AppDelegate).managedObjectContext In Xcode 8 there is no code for managedObjectContext inside AppDelegate.swift file. Core Data stack code inside AppDelegate.swift presented only with: lazy var persistentContainer: NSPersistentContainer property and func saveContext () .

Express for loops in swift with dynamic range

◇◆丶佛笑我妖孽 提交于 2019-12-17 04:07:26
问题 ...or how can I use the index inside the for loop condition Hey people Since we're left with no c style for loops in swift 3 I can't seem to find a way to express a bit more complex for loops so maybe you can help me out. If I were to write this for(int i=5; num/i > 0; i*=5) in swift 3 how would I do that? The closes I came by was: for i in stride(from: 5, through: num, by: 5) where num/i > 0 but this will of course iterate 5 chunks at a time instead if i being: 5, 25, 125 etc. Any ideas?

What is the 'open' keyword in Swift?

我只是一个虾纸丫 提交于 2019-12-17 02:55:48
问题 The ObjectiveC.swift file from the standard library contains the following few lines of code around line 228: extension NSObject : Equatable, Hashable { /// ... open var hashValue: Int { return hash } } What does open var mean in this context, or what is the open keyword in general? 回答1: open is a new access level in Swift 3, introduced with the implementation of SE-0117 Allow distinguishing between public access and public overridability It is available with the Swift 3 snapshot from August

Swift 3 URLSession.shared() Ambiguous reference to member 'dataTask(with:completionHandler:) error (bug)

谁说我不能喝 提交于 2019-12-16 20:04:02
问题 Hello I have working json parsing code for swift2.2 but when i use it for Swift 3.0 gives me that error ViewController.swift:132:31: Ambiguous reference to member 'dataTask(with:completionHandler:)' My codes here let listUrlString = "http://bla.com?batchSize=" + String(batchSize) + "&fromIndex=" + String(fromIndex) let myUrl = URL(string: listUrlString); let request = NSMutableURLRequest(url:myUrl!); request.httpMethod = "GET"; let task = URLSession.shared().dataTask(with: request) { data,

How to input currency format on a text field (from right to left) using Swift?

北城以北 提交于 2019-12-16 19:44:38
问题 I have a number let’s say 0.00 . When the user taps 1. We should have 0.01 When the user taps 2. We should display 0.12 When the user taps 3. We should display 1.23 When the user taps 4. We should display 12.34 How can I do that with Swift? 回答1: For Swift 3 . Input currency format on a text field (from right to left) override func viewDidLoad() { super.viewDidLoad() textField.addTarget(self, action: #selector(myTextFieldDidChange), for: .editingChanged) } func myTextFieldDidChange(_ textField

Swift optional parameter not unwrapped

可紊 提交于 2019-12-16 18:05:13
问题 I have a function with a optional parameter(position). I test for it to be nil but still Xcode shows me an error: "Value of optional type Int? not unwrapped" and suggests me to use "!" or "?". var entries = [String]() func addEntry(text: String, position: Int?) { if(position == nil) { entries.append(text) } else { entries[position] = text } } Im new to Swift and don't understand why this isn't ok. Within this if-clause the compiler should be 100% sure that position is defined, or? 回答1: There

UISwitch not deallocating

陌路散爱 提交于 2019-12-14 04:19:59
问题 This is a repost of my question before but because of too many edit's and I've simplified my examples, I thought it would be more clear if I create a new question instead of re-edit the questions multiple times. PROBLEM: UISwitch object somehow doesn't deallocate even when nothing has been done with it. PROJECT: There are only two view controllers. VC1 and VC2. VC1 has one button to present VC2. VC2 contains one button to dismiss itself and a property of a custom UISwitch , UILabel and a

UICollectionView broken after Swift 3 migration?

百般思念 提交于 2019-12-14 03:53:33
问题 After using the Swift 3 converter on my project, I keep crashing when loading a subclass of a UICollectionViewController. Below is my code with the relevant methods for the collection view. override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return photos.count } override func collectionView(_ collectionView: UICollectionView, c`enter code here`ellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = collectionView