aodelus
aodelus
iOS 13, SwiftUI and other ramblings.
6 posts
Stay up to date.
Don't wanna be here? Send us removal request.
aodelus · 6 years ago
Text
iOS 13, SwiftUI and older devices like the iPhone 6.
There's a lot of talk about iOS 13 and SwiftUI. It's a much more programatically pure way of building simple interfaces or initial interfaces in Swift. It's fantastic!
However, older Apple devices are not going to support iOS 13 or SwiftUI, at least that is the current rumor as of mid August 2019.
Have no fear though, you can have your apps know the difference and still use the existing UIView elements (which are in iOS 12) to be able to support them.
You'll first need to change the iOS Deployment target to 12.4 on both the Project Info and the Project Build Settings. Make sure it's also set that way in the Project Target Build Settings.
After that you'll need to exclude any declarations in your Swift code that use SwiftUI from being used when the iOS version is less than 13.0
Here's how to apply #available to differentiate between iOS versions.
if #available(iOS 13.0, *) { // code for iOS versions greater than 13.0 } else { // code for iOS versions less than 13.0 }
You can use it to include or exclude an entire func, struct, protocol, class or any other declaration.
You will need to use this in SceneDelegate, AppDelegate and of course any other swift files where you have declarations that use SwiftUI.
@available(iOS 13.0, *) struct ContentView: View { }
The last thing you'll have to do in order to have the project work on both iOS 12.4 and iOS >13.0 is remove the SwiftUI Framework and re-add it as optional rather than required.
In the left pane in XCode, right click on SwiftUI.framework within Frameworks and delete it. Then go to the Project Target Build Phases and open Link Binary With Libraries. Click the + to add a new library, select SwiftUI and click Add. Once it's added on the Build Phases page you'll see the Status is set to Required, change it to Optional.
Here are the devices iOS 13 runs on.
iPhones iPhone XS iPhone XS Max iPhone XR iPhone X iPhone 8 iPhone 8 Plus iPhone 7 iPhone 7 Plus iPhone 6s iPhone 6s Plus iPhone SE iPod touch (7th generation)
Apple has dropped support for iPhone 5s, iPhone 6, and iPhone 6 Plus.
iPads
12.9-inch iPad Pro 11-inch iPad Pro 10.5-inch iPad Pro 9.7-inch iPad Pro iPad (6th generation) iPad (5th generation) iPad mini (5th generation) iPad mini 4 iPad Air (3rd generation) iPad Air 2
Apple has dropped support for iPad mini 2, iPad mini 3, and the original iPad Air.
2 notes · View notes
aodelus · 6 years ago
Text
App Icon Generator
Here's a good one - https://appicon.co/
Just copy the images and Contents.json to the AppIcon directory.
1 note · View note
aodelus · 6 years ago
Text
More SwiftUI Parser bugs, tried resizing a Text() object yet?
Look at this.
Text(self.play_status) .padding() .background(Color.red) .foregroundColor(color) .cornerRadius(5) // ensure the size of this object is fixed (won't adjust) .fixedSize(horizontal: true, vertical: true) // set the width to 200 .frame(width: 200)
But if you order the options like this, it will work. How messed up is that!?
Text(self.play_status) // ensure the size of this object is fixed (won't adjust) .fixedSize(horizontal: true, vertical: true) // set the width to 200 .frame(width: 200) .padding() .background(Color.red) .foregroundColor(color) .cornerRadius(5)
0 notes
aodelus · 6 years ago
Text
Would you believe there’s a parser bug? padding() in SwiftUI
If you are using SwiftUI and buttons with text and padding as well as a background color, you might notice a bug.
I'm sure the Apple devs are hard at work submitting bug reports and fixing this one!
If you put .padding() after .background(), the padding won't be applied to the Text() element! GASP!
struct ContentView : View { @State var color = Color.yellow @State var play_status = "Pause" var body: some View { Button(action: { if (self.color == Color.yellow) { self.color = Color.red self.play_status = "Play" player?.pause() } else { self.color = Color.yellow self.play_status = "Pause" player?.play() } }) { Text(self.play_status) .background(color) .padding() } } }
But if you move .padding() before .background() they both work as you would expect. They must have a serious parsing issue with SwiftUI, guess that's why it's still Beta.
struct ContentView : View { @State var color = Color.yellow @State var play_status = "Pause" var body: some View { Button(action: { if (self.color == Color.yellow) { self.color = Color.red self.play_status = "Play" player?.pause() } else { self.color = Color.yellow self.play_status = "Pause" player?.play() } }) { Text(self.play_status) .padding() .background(color) } } }
0 notes
aodelus · 6 years ago
Text
What happened to viewDidLoad() in SwiftUI?
If you were used to viewDidLoad() existing in the UIViewController, don’t expect it to work like you think.
Every time your root view controller was loaded, this was called and you could easily have an entry point for your code each time the user opened your app, regardless of if the app was running the background or not.
class ViewController: UIViewController {   override func viewDidLoad() {       super.viewDidLoad()       // Do any additional setup after loading the view.   } }
With SwiftUI, that’s gone!
Now you don’t have the concept of a keyWindow, something you’ll notice if trying to use keyWindow in iOS 13.  It is being deprecated.
Now when you load a View which conforms to the View Protocol, there’s a special function that allows you to insert your code.
Welcome to the age of onAppear()
struct ContentView : View {   @State var color = Color.yellow   @State var play_status = "Pause"   var body: some View {       Button(action: {           if (self.color == Color.yellow) {               self.color = Color.red           } else {               self.color = Color.yellow               self.play_status = "Pause"           }       }) {           Text(self.play_status)           .background(color)       }.onAppear {           print("ContentView appeared")       }   } }
0 notes
aodelus · 6 years ago
Text
Working Programatically with SwiftUI and iOS 13.
So you've read all the tutorials on SwiftUI and put together a project that works. You've added a button and you can click it.
You might have even setup some @Scoped variables, but you don't really know how they work.
Here's exactly how to work with SwiftUI and maintain the power to click one of those buttons and add 50,000 images and input fields that you fetched from a JSON endpoint or anything else you can possibly dream up.
Keep the root structure simple and work with SwiftUI! Happy Hacking.
import SwiftUI func play_button(images: [String]) -> [String] { print("button clicked") // add a new item to strings each time this is clicked var imgs: [String] = [] imgs.append(contentsOf: images) imgs.append(String("test")) var text = UITextView.init(frame: CGRect(x: 50, y: 100, width: 100, height: 20)) text.text = imgs[0] // add to first window UIApplication.shared.windows.first?.addSubview(text) // add above all windows //UIApplication.shared.keyWindow?.addSubview(text) return imgs } struct ContentView : View { // @State is used to indicate that anytime // a variable declared with @State is modified // the View will update itself or refresh // you can pass @State variables within Button or // other element actions in order to externally modify // elements within a SwiftUI View // // so if you wanted to add a bunch of cells or something // when you clicked something, you could just have the action // modify a @State variable then the view would update itself @State var test = false @State var images: [String] = [] // @EnvironmentObject variables are accessible throughout // all SwiftUI Views var body: some View { Button(action: { // self.body can be used to modify the body View //print(self.body) self.images = play_button(images: self.images) print(self.images) }) { Text("test") } } } #if DEBUG struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } } #endif
1 note · View note