This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import SwiftUI | |
import PlaygroundSupport | |
let allTexts = ["one", "two", "three", "four", "five"] | |
let selectedTexts = ["two", "four"] | |
struct TestView: View { | |
@State private var expanded = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import Combine | |
/** | |
I have two objects, Foo and Bar. Bar is a classic NSObject that hat a KVO observable Value thatchanges on an arbitrairy thread. | |
Foo is an ObservableObject with a published value that is derived from bar. That published value should change in the Main thread so SwiftUI does not complain. | |
However, if I do it with the Publisher/Combine solution only the initial value is nil, and the UI flickers. Instead I want to set the inital value in the init to the current value, and use the publisher only for new values and no longer for initial values. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
class Foo<Value> { | |
init(value: Value) { | |
self.value = value | |
} | |
let value: Value | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import SwiftUI | |
import Combine | |
import PlaygroundSupport | |
struct Model { | |
@AppStorage(wrappedValue: true, "Test") var isEnabled | |
} | |
struct MyView: View { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
/** | |
Here's the challenge: | |
- The Airplane should usually be *centered in the cell*, so they are underneath each other in multiple cells. | |
- No city should overlap the the airplane. If so the airplane should move to the left or the right. | |
- If the space for the airplane is too small, it should not appear. | |
I know in UIKit this can easily be done with a handful of AutoLayout constraints and priorities. | |
But what is the way to do this in SwiftUI? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct TestView: View { | |
var body: some View { | |
ScrollView { | |
VStack { | |
Text("Text Before") | |
ScrollView(.horizontal) { | |
Text("Scrollable Text") | |
.border(Color.red) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Here is what I want to write, and what Xcode sees. */ | |
struct Loc { | |
struct someDomain { | |
/// Here is some description of what this string is doing. It's readable in the AutoComplete Description! | |
static let myStringName = "Woah, woah, this is the actual content of the String!" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct CharacteristicValue { | |
let format: Int8 | |
let exponent: Int8 = -1 | |
let unit: UInt16 | |
let namespace: Int8 | |
let descriptionInfo: Int16 | |
} | |
var value = CharacteristicValue(format: 14, unit: 0x272F, namespace: 1, descriptionInfo: 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
func doStuff<T:CollectionType where T.Generator.Element: Equatable, T.Index.Distance == Int>(collection:T) { | |
//Do Stuff | |
} | |
var list: [Any] = [1,2,2,3,4,5] //This HAS to be saved as [Any]. Or is there another way to specify all kinds of collections that would work with doStuff()? | |
doStuff(list) //This fails: cannot invoke 'doStuff' with an argument list of type '([Any])' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Is there any way to use the Options from libxml2 with the cool new `OptionSet` Syntax from Swift 2? | |
//This is how I do it now | |
let options = Int32(HTML_PARSE_RECOVER.rawValue | HTML_PARSE_NOWARNING.rawValue | HTML_PARSE_NOERROR.rawValue) | |
// ideally I want this, but it doesn't work | |
let options: htmlParserOption = [HTML_PARSE_RECOVER, HTML_PARSE_NOWARNING, HTML_PARSE_NOERROR] | |
//here's the typedef from libxml/HTMLparser.h | |
/* |
NewerOlder