Post

Replies

Boosts

Views

Activity

Spacing between stack views
I work with the storyboard. I have a view controller with a stack view (axis: horizontal, alignment: fill, distribution: fill equally, spacing: 10), but the spacing is not shown in the simulator. The two views of the stack views have to be equally wide. Is there any configuration, which I can change to make the spacing visible?
0
0
288
Jun ’21
Get size of subviews or/and UI elements through code
I have an App which works with stack Views, to create a good looking UI. To make the App even prettier I want to add color gradient for table view cells and other elements which have a fixed size, this is not a problem. For subviews which change the size depending on the device and orientation it is. let topLayer = CAGradientLayer()         topLayer.frame = CGRect(x: 0, y: 0, width: 9000, height: 70)         topLayer.colors = [UIColor(red: 0.13, green: 0.22, blue: 0.35, alpha: 0.80).cgColor , UIColor(red: 0.18, green: 0.26, blue: 0.39, alpha: 1.00).cgColor]         topLayer.locations = [0.0, 1.0]         topView.layer.insertSublayer(topLayer, at: 0) This is how I create the gradient color. How can get the CGRect Values of a subview or is there another way to gradient color without using the frame of CAGradientLayer ?
6
0
1.2k
Apr ’21
When has the AVSpeechSynthesizer finished reading?
I have a Speech Synthesizer which reads the content of my TableView to the User, if the Speech Synthesizer speaks I want to display a pause symbol and if the Speech Synthesizer does not speak- in case of finished reading or stopped by user or did not start reading at all- I want to display a play symbol. This is what I tried but now the button image does not change at all. @IBAction func didTapPlay(_ sender: Any) {         if instance.isSpeaking {             instance.stopSpeaking(at: .word)             play.setImage(UIImage.init(systemName: "play.fill"), for: .normal)         }         else{             changeOutputString(command: "read")             play.setImage(UIImage.init(systemName: "pause"), for: .normal)             stillSpeaking()         }     }     func stillSpeaking(){         var goingon = true         while goingon {             if instance.isSpeaking{                 play.setImage(UIImage.init(systemName: "pause"), for: .normal)                 goingon = false                 }             Timer.scheduledTimer(withTimeInterval: 1.0, repeats: false){_ in                 print("still waiting")             }         }         play.setImage(UIImage.init(systemName: "play.fill"), for: .normal)     }
2
0
1k
Apr ’21
insert Json file into core Data
I have two json files and want to insert them into core data. Therefor I'd like to convert the json into a dictionary (maybe it is as simple as in python?) and insert the key value pairs one by one into core Data. The json is build as followed: {1 : { "title" : "Mini pork pies with piccalilli", "category" : "meat"}, 2 : {"title" : "apple crumble", "category" : "dessert"}} I only was able to get the json file and hopefully converted it into a dictionary (as you can see in the code below). Now I do not know what to do next. let asset = NSDataAsset(name: "Captions")         let data = (asset?.data)!         do{             let json = try JSONSerialization.jsonObject(with: data, options: [])             if let object = json as? [Int : Any] {                 print(object)                 return json as! DictionaryInt, AnyObject             }else if let object = json as? [Any] {                 for anItem in object as! [DictionaryInt, AnyObject]{                    print("Not an dictionary, think of something else")                 }             }
4
0
3.8k
Apr ’21
Table view is not shown in the simulator
I used the storyboard and horizontal and vertical stack views to generate a good looking App. This worked fine, but one view does not show the Table View I placed there. In the storyboard everything is fine and no warning is shown. I tried to remove the Table View and renew it, but that did not fix the problem. Has anybody an idea what I missed ?
3
0
2.4k
Mar ’21
Need notification in code, if user change View
I am using an AVSpeechSythesizer(), which reads the list (TableViewCells) on one view to the user, if the user hits a button. If the user hits the button again the AVSpeechSynthesizer() stops, as I want it to be. But I want the AVSpeechSynthesizer() to stop as well, if the user change the view (go back or hit the home Button). Is it possible that the ViewController of that view get Notification, if the View is no longer shown or have I to check in the other ViewControllers?
3
0
396
Mar ’21
Convert String.index into int
I have a long String which I want to shorten step by step. The String contains a lot of characters which I don't need, but the String has some patterns, so I search for a character, shorten the original String or rather the copy of the original String and search for the next relevant character. let searchname = ""         let f = globalString.firstIndex(of: "\"")         self.globalString.dropFirst(f)         let e = globalString.firstIndex(of: "\\")         let substring = globalString[...e!]         return String(substring) In line three I get the error, that an Integer is needed and a String.index is given. How can I transform the String.index to an Integer or is there another possibility to this in code?
2
0
2.2k
Feb ’21
Context Files after xcode crash empty/Persistent data in core Data
Xcode crashed unexpectedly last week. After restarting, Xcode had a problem so I restarted my MacBook. I reopened Xcode and started a simulation and no Data where shown, so I debugged through my code and the Context file seems to be empty. Now I have several questions: 1) Has anybody an idea why this happened ? 2) How can I prevent this problem? 3) Are context files for persistent data savings anyway?
0
0
356
Feb ’21
Create a blinking label
I have a normal label and want that Label to blink three times, by changing the backgroundcolor from red to black an so on. I did some research and many people work with Timer or animations, but I cannot change this methods, like I need them. What can I do to make my Label blink?
6
0
2.9k
Jan ’21
Pass Data between two View Controller
I have two View Controller, lets call them A1 and A2. A1 has consits of a tableView with various entries. If I click on an entry namend "Orange" in A1, A2 should show details about Orange. To store the data I use Core Data. I filter the data I need for the Orange in A1 and now I want to pass the data like name, size etc. to A2. I tried to use a function in A1 wich sets the variables in A2. This works but when I perform the segue all the data is gone. What can I do to pass the data? func initializer(caption: String, size : String, text: String) {         self.text = text         self.fruitCaption = caption         self.fruitSize = size     } I call this initializer function from A1, the function itself is placed in A2.
5
0
1.9k
Dec ’20
Change the table content in one viewController
I have a four buttons and one table view in one viewController. I want to select the entries in my table with the button. E.g. I have a list of persons and one button says "family" one "friends" one "collegues" and one "unknown" by clicking on one button the table only should show the persongroup I selected. The entries of the table view are stored in an global array. Changing the array with clicking is possible (I see this in the command line), but the table does not change. Does any one know why ? For storing and selecting data I use core data. In the IBAction I do this:         guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else{             return         }         let context = appDelegate.persistentContainer.viewContext         let entityName = "Person"         let request = NSFetchRequest<NSFetchRequestResult>(entityName: entityName)         let pred = NSPredicate(format: "relationship_status CONTAINS 'friend'")         request.predicate = pred         do {             let results = try context.fetch(request)             for r in results{                 if let result = r as? NSManagedObject{                     guard let relationship_status = result.value(forKey: "relationship_status") as? String else {                         return                     }                     guard let name = result.value(forKey: "name") as? String else {                         return                     }                     self.table_entries.append(name)                     print("load")                 }             }             print ("done")             print (table_entries)         } catch  {             print(error)         }
4
0
434
Dec ’20
Trouble with installing cocoapods
I am getting the same error over and over again and I do not know why. I tried several ways to fix it, but nothing works. Building native extensions. This could take a while... ERROR:  Error installing cocoapods: ERROR: Failed to build gem native extension.     current directory: /Library/Ruby/Gems/2.6.0/gems/ffi-1.13.1/ext/ffi_c /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /Library/Ruby/Site/2.6.0 -r ./siteconf20201202-2686-t7m7nb.rb extconf.rb checking for ffi.h... * extconf.rb failed * Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers.  Check the mkmf.log file for more details.  You may need configuration options. Provided configuration options: --with-opt-dir --without-opt-dir --with-opt-include --without-opt-include=${opt-dir}/include --with-opt-lib --without-opt-lib=${opt-dir}/lib --with-make-prog --without-make-prog --srcdir=. --curdir --ruby=/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/$(RUBY_BASE_NAME) --with-ffi_c-dir --without-ffi_c-dir --with-ffi_c-include --without-ffi_c-include=${ffi_c-dir}/include --with-ffi_c-lib --without-ffi_c-lib=${ffi_c-dir}/lib --enable-system-libffi --disable-system-libffi --with-libffi-config --without-libffi-config --with-pkg-config --without-pkg-config /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:467:in `try_do': The compiler failed to generate an executable file. (RuntimeError) You have to install development tools first. from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:585:in `block in try_compile' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:534:in `with_werror' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:585:in `try_compile' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1109:in `block in have_header' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:959:in `block in checking_for' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in `block (2 levels) in postpone' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in `open' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in `block in postpone' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in `open' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:357:in `postpone' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:958:in `checking_for' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1108:in `have_header' from extconf.rb:10:in `system_libffi_usable?' from extconf.rb:42:in `<main>' To see why this extension failed to compile, please check the mkmf.log which can be found here:   /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/ffi-1.13.1/mkmf.log extconf failed, exit code 1 Gem files will remain installed in /Library/Ruby/Gems/2.6.0/gems/ffi-1.13.1 for inspection. Results logged to /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/ffi-1.13.1/gem_make.out Something might be wrong with Ruby, but I could not figure out what I should do to fix it.
21
5
85k
Dec ’20