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 ContentView: View { | |
var body: some View { | |
Path { path in | |
path.move(to: CGPoint(x: 100, y: 100)) | |
path.addLine(to: CGPoint(x: 100, y: 300)) | |
path.addLine(to: CGPoint(x: 300, y: 300)) | |
path.addLine(to: CGPoint(x: 100, y: 50)) | |
} | |
.fill(Color.yellow) |
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 UIKit | |
@IBDesignable class SingleBorderedTextField: UITextField { | |
private var bottomBorder = UIView() | |
private (set) var lineStrength: CGFloat = 1 | |
@IBInspectable var lineWidth: CGFloat { | |
get { | |
return self.lineStrength |
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
realm.beginWrite() | |
cat.name = "Matilda" | |
try! realm.commitWrite() |
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
let config = Realm.Configuration( | |
schemaVersion: 1, | |
migrationBlock: { migration, oldSchemaVersion in | |
print("migration succeeded") | |
}) | |
Realm.Configuration.defaultConfiguration = config |
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
class Cat: Object { | |
@objc dynamic var catId: Int = 0 | |
@objc dynamic var name: String = "" | |
@objc dynamic var breed: String = "" | |
@objc dynamic var weight: Double = 0 | |
override static func primaryKey() -> String? { | |
return "catId" | |
} |
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
let cats = realm.objects(Cat.self).filter("name = 'Tigger'") | |
for cat in cats { | |
realm.beginWrite() | |
cat.owner = cat.person.first | |
try! realm.commitWrite() | |
if let owner = cat.owner { | |
print("\(owner.firstName) \(owner.lastName)") | |
} | |
} |
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
let config = Realm.Configuration( | |
schemaVersion: 1, | |
migrationBlock: { migration, oldSchemaVersion in | |
print("migration succeeded") | |
}) | |
Realm.Configuration.defaultConfiguration = config |
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
@objc dynamic var owner: CatPerson? = nil | |
let person = LinkingObjects(fromType: CatPerson.self, property: "cats") | |
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
let realm = try! Realm() | |
try! realm.write { | |
realm.deleteAll() | |
} | |
let serializer = JSONSerializer() | |
serializer.serialize(input: "CatPeople") |
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 RealmSwift | |
class JSONSerializer { | |
func serialize(input sourceName: String) { | |
let path = Bundle.main.path(forResource: sourceName, ofType: nil) | |
let url = URL(fileURLWithPath: path!) | |
let jsonDecoder = JSONDecoder() | |
do { | |
let data = try Data(contentsOf: url) |
NewerOlder