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
print(Thread.current) //可以调试当前的thread |
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 Foo:Object { | |
dynamic var id:Int = 0 | |
dynamic var name:String = "" | |
override class func primaryKey() -> String? { | |
return "id" | |
} | |
} | |
let bar = Foo() |
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 Foo { | |
var name:String | |
} | |
let bar = Foo(name:"John") |
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 Foo:Object { | |
dynamic var name:String = "" | |
} | |
let bar = Foo() | |
let realm = try! Realm() | |
try! realm.write { | |
realm.add(bar) | |
} |
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 bar = Foo() | |
bar.name = "Marry" // ok | |
let realm = try! Realm() | |
try! realm.write { | |
realm.add(bar) | |
bar.name = "Kelly" // ok | |
} | |
bar.name = "Jimmy" // *** Terminating app due to uncaught exception 'RLMException', reason: 'Attempting to modify object outside of a write transaction - call beginWriteTransaction on an RLMRealm instance first.' |
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 anotherBar = Foo() | |
anotherBar.name = bar.name | |
try! realm.write { | |
realm.add(anotherBar) | |
} |
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 anotherBar = Foo() | |
anotherBar.name = bar.name | |
try! realm.write { | |
realm.add(anotherBar) | |
realm.delete(bar) | |
} |
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 Fruit:Hashable { | |
let name:String | |
var hashValue: Int { | |
return name.hashValue | |
} | |
init(name:String) { | |
self.name = name | |
} |
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 Apple:Fruit { | |
override var hashValue: Int { | |
return super.hashValue - "apple".characters.count | |
} | |
} | |
class Banana:Fruit { | |
override var hashValue: Int { | |
return super.hashValue - "banana".characters.count | |
} |
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 Fruit:Hashable { | |
let name:String | |
var hashValue: Int { | |
return name.hashValue | |
} | |
init(name:String) { | |
self.name = name | |
} |
OlderNewer