Important: Just because you can move over to SwiftData, it doesn't mean you should. If you already have an app built with Core Data and want to move it to SwiftData, you'll be pleased to know that the two are almost entirely compatible at the data layer – all your Core Data models will move across smoothly, with all user data preserved. There are a couple talks on that from WWDC which would be a great resource to learn more.How to migrate an app from Core Data to SwiftData I haven’t worked with the debugger or the refactoring option. Q: How helpful is XCode with refactoring or things like debugging?ĭavid: I think the error messages I’ve gotten in Swift so far are a little bit cryptic, but there have been updates on Swift debugging. AnyType can contain any value type or reference type. Q: Does Swift have the ID type? How can you declare a variable of the protocol type?ĭavid: In Swift there is no ID, but there is the type AnyObject which can contani any reference type. Q: What if you don’t have an init in a class that just has methods? I had an SKView class deriving from base classes and kept having a strange pilot error.ĭavid: Another thing to keep in mind is that if it’s implementing a protocol that has a required keyword on an init, then you need to define those required inits that don’t get inherited. There are special circumstances where they do get inherited, for example when you have no store properties, but once you decalre a non-Optional property, you have to take care of the initializers. Q: Does having the convenience keyword make anything easier to decipher? Because I found it strange that in my project I had to go through my class heirarchy to find every init and redefine them in my class.ĭavid: Initializers are not by default inherited in Swift. If you were declare something instead as private, you can’t access the property of that class anywhere else in your app. This can be used anywhere within your application. Q: About public, private, and internal - how do you define internal? What are the boundaries for that?ĭavid: Internal means that your property can be used with a class-type. I think I might start with some of the data part so you don’t have two separate files managing the data of something. Q: When you want to take an app and convert it to Swift, where is a good place to start based on your BNR guide?ĭavid: I haven’t incrementally converted a large app, just smaller projects. Person 2: I’ve worked that a little, I think at the moment you declare your property to be dynamic and use Objective-C stuff to do key-value observing in Swift. ![]() I prefer the structures you work with in Swift.ĭavid: I haven’t worked with that much in OBjective-C or Swift, so I couldn’t say for sure. However, I think it’s much less likely to run into as many programmer bugs and it’s probably a little bit faster to code. Q: Have you seen any big advantages of using Swift?ĭavid: I wouldn’t say there have been massive gains in terms of shorter code. Overall it just ends up being cleaner code. There are a lot of different quirks in Swift and I think it prevents a lot of developer errors that can be fairly common in Objective-C. Q: Could you tell us more about your github project on translating everything? How far are you into the peoject and are there any kind of overarching lessons you’ve learned?ĭavid: I’m about halfway through the project, about 13 chapters so far. Q: If you have a lot of initializers, the first one doesn’t need any special keywords but subsequent ones require the keyword “convenience”?ĭavid: You need an initializer that makes sure that all your stored non-optional properties are initialized. It infers the type because of the function signature.Ĭlass RecipeIngredient : Food Q&A (24:05) Swift allows you to shorten the name to “.Normal” when you pass that value into a parameter. In this case, you could have an enum of type UIControlState with highlighted, normal, and different values associated with it. In Swift, you can add a dot before the last word. Value Types Using Enums (0:57)Įnums in Objective-C tend to have very long enum names, one example being UIControlStateNormal. This affects how these data structures are used in Swift. In Objective-C, these structures were classes. ![]() Structs in Swift include arrays, dictionaries, and strings. You can find a blog version of the talk (with code samples) below. In his SLUG presentation at ThoughtWorks, he covered a range of topics, including Swift data types and mutability of types, and converting Objective-C code into Swift.Īs usual, video & slides are synchronized. Soon after Swift came out David Kobilnyk set out on an interesting quest: to convert all the Objective-C code samples in the seminal book “ iOS Programming: The Big Nerd Ranch Guide” to Swift.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |