2010-10-08 SpaceWire at SRON
The purpose of SpaceWire (short: SpWi), is a standard to connect pieces of a satellite for data retrieval . . . The missions [http://en.wikipedia.org/wiki/Swift_Gamma-Ray_Burst_Mission SWIFT] and the [http://en.wikipedia.org/wiki/Lunar_Reconnaissance_Orbiter . . .
4K - last updated 2010-10-08 08:54 UTC by 1413
2014-11-18 Swift optionals
Recently I dived into Swift and in order to grok optionals, first read this article on Medium: [https://medium.com/@rrridges/swift-optionals-a10dcfd8aab5 . . . Swift Optionals] and then [http://stackoverflow.com/a/24020951/1085556|this . . .
1K - last updated 2014-11-18 13:08 UTC by 1413
2015-01-29 Update interface when app is opened
If you're developing in Swift and want to update your app's interface when it's reopened, put the following . . .
2K - last updated 2015-01-29 11:29 UTC by 1413
2015-02-05 Swift example of a batch update in Core Data
Here's a Swift example of doing a batch update in Core Data: let updateRequest = NSBatchUpdateRequest("some_entity_name") . . .
1K - last updated 2015-02-05 15:28 UTC by 1413
2015-02-06 Swift enum raw values as an array
Here's a quick example of using Swift's map() function. Here it's used to put the raw values of an enum . . . How it looks in a playground: [[image:swift_enum_raw_values_as_array_playground.png]] . . .
1K - last updated 2015-02-06 09:10 UTC by 1413
2015-06-21 Swift 2.0 error handling
Here is a [http://ericasadun.com/2015/06/18/swift-asynchronous-error-handling/ nice article by Erica . . . Sadun] on the error handling in Swift 2.0. I really like how a ''try'' statement can . . .
2K - last updated 2015-06-21 17:51 UTC by 1413
2015-07-05 withUnsafeBufferPointer
Update 2016-10-06; a very nice (and updated for Swift 3) blog about this: http://technology.meronapps.com/2016/09/27/swift-3-0-unsafe-world-2/ . . .
1K - last updated 2016-10-06 06:15 UTC by 1413
2015-08-07 Core Data sum example
I had some trouble last week finding a Swift example to sum across order line entities in Core Data. . . .
2K - last updated 2015-08-07 14:39 UTC by 1413
2015-08-07 Swift Reflect example
Halfway last month, Erica Sadun wrote a blog entry where she used the <tt>reflect()</tt> function: [http://ericasadun.com/2015/07/14/swift-just-because/ . . . Swift: Just because] She just gave the code and didn't . . . take an item that can be basically anything in Swift // and look through the names of its members . . . : Any, key: String) -> Any? { // The built-in Swift reflect() function is used by Xcode to aid in . . . println(mirror[0].1.value) [[image:swift_reflect.png]] . . .
2K - last updated 2015-08-07 15:27 UTC by 1413
2015-08-21 lastPathComponent is unavailable
You may get something like the following error when you open your Swift code in Xcode 7 beta: 'lastPathComponent' . . .
1K - last updated 2015-08-21 13:15 UTC by 1413
2015-08-27 Swift Switch must be exhaustive
In Swift, the switch/case statement must contain a default case, otherwise you'll get the following compiler . . .
1K - last updated 2015-08-27 13:31 UTC by 1413
2015-11-26 Delay initialization of constant variable in Swift
Recent versions of Swift allow making a variable constant (with the <tt>let</tt> keyword), without directly . . .
1K - last updated 2015-11-26 11:34 UTC by 1413
2015-12-11 Measuring startup time
The startup time of your app is determined by a bunch of things, but one that you can easily and directly . . . the following code at the top of the AppDelegate.swift file. var logTimer: CFTimeInterval = -1.0 var . . .
2K - last updated 2015-12-11 09:11 UTC by 1413
2016-02-18 Swift error Instance member cannot be used on type
Today, Swift gave me the error: Instance member "membername" cannot be used on type "Classname" The code . . .
1K - last updated 2016-02-18 07:56 UTC by 1413
2016-02-19 Swift example of regex
Here's a quick-and-dirty copy-paste example of a regex in Swift 2.0. It pulls the width and height as . . .
1K - last updated 2016-02-19 06:05 UTC by 1413
2016-04-16 Codility supports Swift
If you didn't know [https://codility.com/programmers/ Codility]: it's a company that devises programming . . . solving programming puzzles. And now it supports Swift! I've been having fun doing some small puzzles . . .
2K - last updated 2016-04-16 19:34 UTC by 1413
2016-04-24 Swift solution to StoneWall
This is a 100% scoring solution to the Codility StoneWall problem. Note the bunch of print statements . . .
2K - last updated 2016-04-24 11:29 UTC by 1413
2016-05-24 Swift example of CoreData max query
Here's a copy/paste example of doing the equivalent of a SQL MAX() function. I know, I know "CoreData . . .
2K - last updated 2016-05-24 11:16 UTC by 1413
2016-08-16 Filter array in Swift
Here's a bit of code that you can throw in a playground. Given an array with a bunch of objects, it'll . . .
1K - last updated 2016-08-16 11:36 UTC by 1413
2016-09-13 weird error when creating constraint in Swift 3
Today, I've transitioned a project to Swift 3 and I bumped into a crash. The crash was as follows: -[_SwiftValue . . . 'NSInvalidArgumentException', reason: '-[_SwiftValue nsli_superitem]: unrecognized selector sent . . .
2K - last updated 2016-09-14 08:41 UTC by 1413
2016-09-22 Swift 3 naming
Swift 3 is different from version 2 in the naming department. The short version is that the first label . . . -> [VIFormPageView] See also: https://swift.org/documentation/api-design-guidelines/ . . .
1K - last updated 2016-09-22 08:50 UTC by 1413
2016-10-06 Walking through a String in Swift 3
This is how you walk through a string in Swift 3: let str = "Hello, playground" let stepsize = 3 let . . .
1K - last updated 2016-10-07 07:35 UTC by 1413
2016-10-17 Compare floats in Swift
To compare floats to zero, or each other, use the following functions: func fequal(_ a: Double, _ b: . . .
1K - last updated 2016-10-17 07:26 UTC by 1413
2017-02-02 Swift app without Interface Builder
Here's an example of an AppDelegate.swift, for those who don't like Interface Builder: import UIKit @UIApplicationMain . . .
1K - last updated 2017-02-03 09:03 UTC by 1413
2017-05-09 Check PDF file header with Swift
Here's a little Swift playground that shows how you can check whether a Data object (for example from . . .
2K - last updated 2017-05-09 12:14 UTC by 1413
2017-05-29 Creating a Swift module
When creating a custom view, I find it very useful to make it into a framework and include an example . . . looks logical and good * Create a new Swift file, and add your code there * Then go to menu . . .
1K - last updated 2017-05-29 09:55 UTC by 1413
2017-07-25 Swift dictionary keys to array
The following code can be pasted into a Swift playground, and demonstrates how you can get a mutable . . .
1K - last updated 2017-07-25 07:12 UTC by 1413
2017-09-17 Replacing NSTimer in Swift 4
For repeated calling of a function, the Timer class is available (used to be called NSTimer). So perhaps . . . you had the following code in your Swift 3 project: private var timer: Timer? override . . . // Do something } When you move your project to Swift 4 (via Xcode 9), then first you get the following . . . warning: The use of Swift 3 @objc inference in Swift 4 mode is deprecated. . . . warnings, test your code with “Use of deprecated Swift 3 @objc inference” logging enabled, and then . . .
2K - last updated 2017-09-17 10:09 UTC by 1413
2017-09-25 Swift example of a factory and a closure typealias
I couldn't find a nice, compact example of a closure typealias in Swift, so here is one you can paste . . .
1K - last updated 2017-09-25 13:22 UTC by 1413
2017-10-02 Most popular Swift projects
Here's a nice link to the most popular Swift-related projects on Github: https://github.com/search?utf8=%E2%9C%93&q=stars%3A%3E1+language%3Aswift&type=Repositories . . .
1K - last updated 2017-10-02 09:55 UTC by 1413
2017-10-09 using reduce in Swift
Here's a little playground that shows how to use reduce in Swift, specifically use it to report on a . . .
2K - last updated 2017-10-10 21:55 UTC by 1413
2017-12-23 Showing SVG image without libraries
Recently I had the need to show a logo in SVG format, but the project required that we did not include . . . 3rd party libraries. The following Swift playground shows how you can show an SVG-based . . .
3K - last updated 2017-12-23 13:47 UTC by 1413
2018-01-11 Navigationbar below statusbar on iOS 10
I had the strangest issue today. When testing my current app on iOS 10, the navigation bar would sit . . . and we used the following AppDelegate.swift: @UIApplicationMain class AppDelegate: UIResponder, . . .
2K - last updated 2018-01-11 09:57 UTC by 1413
2018-05-15 Non-existing dates
One William Woodruff wrote a blog entry in 2015 about non-existing dates: https://blog.yossarian.net/2015/06/09/Dates-That-Dont-Exist . . . } else { print("Not a date") } The above Swift code can be pasted into a playground. Supposedly, . . .
1K - last updated 2018-05-15 07:22 UTC by 1413
2019-07-15 Generic parameter subject could not be inferred
In a condensed form, I had the following SwiftUI code: struct Input { var someString = "OH HAI" } struct . . .
1K - last updated 2019-07-15 08:39 UTC by 1413
2020-03-05 Capping an array in Swift
Do you want to cap an array in Swift to a certain size? Here's how: var array = ["a", "b", "c", "d", . . .
1K - last updated 2021-06-01 13:12 UTC by 1413
2020-05-27 Fixing a slow build in Xcode
If your Xcode project isn't compiling as fast as you expect, open the build settings of target that you're . . . building. Add the following to the "Other Swift Flags" setting: -Xfrontend -warn-long-expression-type-checking=100 . . .
1K - last updated 2020-05-27 08:26 UTC by 1413
2020-07-16 Error in SwiftUI preview
Today, one SwiftUI Preview would not show anything. The Diagnostics button showed the following error: . . .
1K - last updated 2021-01-15 07:40 UTC by 1413
2021-01-22 Error in SwiftUI Previews part deux
Today Xcode refused to show previews for one view, displaying "Cannot preview this file" on top of the . . . This time it's showing the error "SomeUnitTest.swift must belong to at least one target in the current . . .
1K - last updated 2021-01-22 10:40 UTC by 1413
2021-03-22 Debugging view sizes
Here's a tip if you wish to show the sizes of views in your SwiftUI previews. Add the following struct . . .
2K - last updated 2021-03-22 08:45 UTC by 1413
2021-09-30 CGRect appendInterpolation
In the category of errors that you google but don't get results. Suppose you have the following state . . . variable in a SwiftUI view: @State private var textFieldFrame1 = . . .
1K - last updated 2021-09-30 13:53 UTC by 1413
2021-10-19 Constrained extension must be declared on the unspecialized generic type
Did you get the following error message in Swift? Constrained extension must be declared on the unspecialized . . .
1K - last updated 2021-10-19 09:37 UTC by 1413
2021-10-20 Generic parameter Destination could not be inferred
Xcode 13.0. If you're banging out SwiftUI code, and you got the following error message: Generic parameter . . .
1K - last updated 2021-10-20 10:53 UTC by 1413
2021-12-02 SwiftUI NavigationLink Extraneous argument label isActive in call
Today, in Xcode 13.1, I got the following error: Extraneous argument label 'isActive:' in call Accompanied . . .
1K - last updated 2021-12-02 15:26 UTC by bartvk
2022-03-03 Xcode Dependencies could not be resolved
Today, Xcode gave me the following error: Dependencies could not be resolved because root depends on . . . so I [https://developer.apple.com/documentation/swift_packages/editing_a_package_dependency_as_a_local_package . . .
2K - last updated 2022-03-03 10:27 UTC by bartvk
2022-03-28 Creating dotted line with StrokeStyle in SwiftUI
Here's an example of stroking a shape with a dotted line: struct ContentView: View { var body: some View . . .
1K - last updated 2022-03-28 12:30 UTC by bartvk
2022-05-23 Xcode Package.resolved file is corrupted or malformed
Today Xcode gave me the error "Package.resolved file is corrupted or malformed; fix or delete the file . . . when opening and running an xcworkspace with a Swift package and a sample app. That is exactly after . . . 2". I'm not yet happy with the way Xcode handles Swift Packages, it feels unreliable in the current . . .
2K - last updated 2022-05-23 09:10 UTC by bartvk
2022-09-15 Xcode linker error ld framework not found
Today I got the following error when trying to build my unittest for my Swift package: ld: framework . . .
1K - last updated 2022-09-15 13:26 UTC by bartvk
2022-11-18 Example of hierarchical list
I actually didn't know that the SwiftUI List element natively supports hierarchical lists, until someone . . .
1K - last updated 2022-11-18 08:31 UTC by bartvk
2022-12-12 When to use StateObject wrappedValue initializer
UPDATE 2023-04-28: Apple updated its documentation: https://developer.apple.com/documentation/swiftui/stateobject#Initialize-state-objects-using-external-data . . . we recently discussed the use of StateObject in SwiftUI. It's very useful for ViewModels. However you . . . [https://developer.apple.com/documentation/swiftui/stateobject/init(wrappedvalue:) Source: developer.apple.com] . . .
2K - last updated 2023-04-28 06:02 UTC by bartvk
2023-02-22 Unselectable picker in SwiftUI
Today I spent too much time looking at a bit of code that wasn't working. Here's the problem: the following . . .
2K - last updated 2023-11-07 10:19 UTC by bartvk
2023-06-14 SwiftUI pet peeves
This is my list of SwiftUI pet peeves. It's a work in progress. * Using .onTapGesture when you should . . . "get" or something else. See also: https://www.swift.org/documentation/api-design-guidelines/ * Hardcoded . . .
1K - last updated 2023-09-18 07:30 UTC by bartvk
2023-08-30 Coordinator in preview
When you're using the Coordinator pattern in a SwiftUI project, you'll find yourself sometimes wanting . . . code needs to be present, to wrap the SwiftUI view in a UIHostingController. This bit of . . . project, and use in the preview section of your SwiftUI view. private class PreviewViewController: . . .
2K - last updated 2023-08-31 11:26 UTC by bartvk
2023-09-18 SwiftUI Separate toolbar
In SwiftUI, it's easy to just keep coding and dump everything in one view. Toolbars especially are "bulky", . . .
1K - last updated 2023-09-22 09:17 UTC by 1413
Swift
== Performance == Quick and dirty snippet to measure time. Here's an example to measure 1 second of sleeping. . . .
1K - last updated 2017-04-11 10:39 UTC by 1413
swift enum raw values as array playground.png
image/png
70K - last updated 2015-02-06 09:09 UTC by 1413
swift module 1.png
image/png
122K - last updated 2017-05-29 09:33 UTC by 1413
swift module 2.png
image/png
117K - last updated 2017-05-29 09:35 UTC by 1413
swift module 3.png
image/png
142K - last updated 2017-05-29 09:35 UTC by 1413
swift module 4.png
image/png
141K - last updated 2017-05-29 09:36 UTC by 1413
swift module 5.png
image/png
246K - last updated 2017-05-29 09:36 UTC by 1413
swift module 6.png
image/png
145K - last updated 2017-05-29 09:36 UTC by 1413
swift module 7.png
image/png
142K - last updated 2017-05-29 09:36 UTC by 1413
swift module 8.png
image/png
162K - last updated 2017-05-29 09:36 UTC by 1413
swift module 9.png
image/png
200K - last updated 2017-05-29 09:36 UTC by 1413
swift new module 1.png
image/png
122K - last updated 2017-05-29 09:50 UTC by 1413
swift reflect.png
image/png
234K - last updated 2015-08-07 15:26 UTC by 1413
67 pages found.