Giter VIP home page Giter VIP logo

unrealm's Introduction

Unrealm Header Logo



Swift 5.1 Build Status Version Platform License Platform Platform


Unrealm enables you to easily store Swift native Classes, Structs and Enums into Realm .
Stop inheriting from Object! Go for Protocol-Oriented programming!
Made with โค๏ธ by arturdev



Features

Unrealm supports the following types:

  • Swift Primitives
  • Swift Structs
  • Swift Classes
  • Swift Enums
  • Swift Arrays
  • Swift Dictionaries
  • Nested Classes/Structs
  • Swift Optionals (String, Data, Date)
  • Swift Optionals of primitives (Int, Float, Double, Bool)
  • Swift Optionals of Realmables
  • Swift Optionals of Arrays
  • Swift Arrays of enums

Example Project

To run the example project, clone the repo, and run pod install from the Example directory first.
See also Unit Tests.

Usage

All you have to do is

  1. Conform your Classes/Structs to Realmable protocol instead of inheriting from Object. Conform your Enums to RealmableEnum protocol.
  2. Register your Classes/Structs and Enums in AppDelegate's didFinishLaunchingWithOptions.
Realm.registerRealmables(ToDoItem.self)

That's it! Now you can store your Struct or Class object into Realm as usually you do with Objc Classes.

Pros and Cons

Pros ๐ŸŽ‰

  • Enables you to store Swift native types (Structs, Classes, Enums, Arrays, Dictionaries, etc...)
  • Getting rid of redundant inheriting from Object class
  • Getting rid of Realm crashes like "Object has been deleted or invalidated"
  • Getting rid of Realm crashes like "Realm accessed from incorrect thread"
  • Getting rid of boilerplate code such as @objc dynamic var. Use just var or let
  • Getting rid of boilerplate code such as RealmOptional<Int>. Use just Int?
  • Works perfect with Swift's Codable and optional types!

Cons ๐ŸŸ

  • Losing "Live Objects" feature. Which means when you modify an object got from Realm the other ones will not be updated automatically. So after modifying an object you should manually update it in realm. f.e.;
let realm = try! Realm()
var todoItem = realm.object(ofType: ToDoItem.self, forPrimaryKey: "1")
todoItem.text = "Modified text"
try! realm.write {
realm.add(todoItem, update: true) //<- force Realm to update the object
}

Installation

CocoaPods

Unrealm is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'Unrealm'

Swift Package Manager

You can also use Swift Package Manager to add Unrealm as a dependency to your project. In order to do so, use the following URL:

https://github.com/arturdev/Unrealm.git

You need to use "master" branch instead of SPM.

ToDos

  • Add more UnitTests
  • Create a sample project for Swift Package Manager when dependencies can be added to many targets in a simple project.

Contribution

โญ๏ธ If you like what you see, star us on GitHub.

Find a bug, a typo, or something thatโ€™s not documented well? Weโ€™d love for you to open an issue telling me what I can improve!

Contributions are welcome, and they are greatly appreciated!

Author

arturdev, [email protected] matghazaryan, [email protected]

License

Unrealm is available under the MIT license. See the LICENSE file for more info.

unrealm's People

Contributors

arturdev avatar corteggo avatar iakashlal avatar matghazaryan avatar moelnaggar14 avatar nnsnodnb avatar reallyram avatar stavares843 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

unrealm's Issues

Add carthage support.

Sucks to use Cocoapods, when the requirements are Realm.
Build time increases by 30 minutes for bigger projects.

Please add carthage support.

Casting custom class fails.

I'm not sure if this is just an error with my code but I have a Realmable that looks like this:

struct AnyEntity: Realmable {
    
    var id: String = ""
    var state: String = ""
    
    var attributes: EntityAttributes? = nil
    
    static func primaryKey() -> String? {
        return "id"
    }
}

The attributes is a class that looks like this:

class EntityAttributes: Realmable {
    required init() {
    }
}

and multiple other custom classes can inherit from EntityAttributes like this:

class LightAttributes: EntityAttributes {
    var brightness: Int? = nil
    var rgbColor: [Int]? = nil
}

Now when I save say for example a LightEntity, as the attributes variable of the AnyEntity Realmable this works fine.

let realm = try! Realm()
                    
let attributes = LightAttributes()
attributes.brightness = 1
attributes.rgbColor = [0, 255, 255]
                    
let newEntity = AnyEntity(entityId: "entity_0", state: "abc", attributes: attributes)
                    
try! realm.write {
    realm.add(newEntity, update: .modified)
}

But when I try to access the saved and cast the attributes variable from EntityAttributes to LightAttributes, it fails.

let realm = try! Realm()

let entity = realm.object(ofType: AnyEntity.self, forPrimaryKey: "entity_0")

// Fails with "Could not cast value of type 'EntityAttributes' (0x1041bf2f0) to 'LightAttributes' (0x1041bf380)."
let attributes = entity!.attributes as! LightEntity

MacOS support

Would it be possible to add MacOS support to Unrealm. Which area of the code is currently preventing Unrealm to run on Mac and needs to be adopt?

Thanks,

How to improve performance on large datasets ?

Hi,

I'm using unrealm to support structs as realm objects. However this comes with a performance hit.

I observed few things. LEts say there are 10k records in realm.

Reading the results from realm is pretty quick, its less than a second for those 10k items.

And when I try to convert them into an array, it becomes too slow. It is only converting 100 items per second into an array, so for 10k items, it is taking 100secs.

Do you recommend any solution to improve the loading speed ?

NOTE: I want to convert the realm results into an array because , I cant use predicates on structs. If I use class, I loose the swift features on struct.

Sample code:

        extension Task {
              static func all() -> Results<Task>? {
                    if let realm = try? Realm() {
                          return realm.objects(Task.self)
                    }
                     return .none
              }
        }
        if let tasks = Task.all() {
            DataManager.shared.tasks = Array(tasks)
        }

Problem with Optionals Dictionnary when retrieving data (Data)

Hi !

I have a problem deserializing Data attribute of my model, when it's type is an optional Dictionary.

Here's an exemple of my model:

`
var id: String = UUID().uuidString
var name: String = ""
var bodyPart: String = ""

var type: String = "normal"
var globalRestTimer: Double = 0.0
var exerciseSpecificRestTimer: [Int: Double] = [0: 0.0]

var exercises: [Exercise]?
var exercisesTargetSets: [Int: Int]?
var exercisesTargetReps: [Int: Int]?

var createdAt: Date = Date()

static func primaryKey() -> String? {
return "id"
}`

I successfully saved data to the Realm, but always get a nil value when reading the data.

I think the problem is in the else if condition, where child.value is [AnyHashable:Any], let data = value as? Data always returns false when using optionals. Unrealm.swift -> readValues(from:)

Therefore, when setting property.set in the else statement, the value (Data) gets nullified.

} else { if let t = property.type as? RealmableEnum.Type, let val = t.init(rlmValue: value) { try property.set(value: val, on: &self) } else if child.value is [AnyHashable:Any], let data = value as? Data { if let json = try NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(data) { try property.set(value: json, on: &self) } } else { try property.set(value: value, on: &self) } }

I've tried different workaround, but I can't make it work.

Does anybody have a solution?

Thanks !

List<Object>

i can not use with list of object, Ex: List, or arr : [Object],
how to use it ?

[!] CocoaPods could not find compatible versions for pod "RealmSwift":

[!] CocoaPods could not find compatible versions for pod "RealmSwift":
  In snapshot (Podfile.lock):
    RealmSwift (= 3.18.0, ~> 3.14)

  In Podfile:
    RealmSwift

    RxRealm was resolved to 1.0.0, which depends on
      RealmSwift (~> 3.14)

    Unrealm was resolved to 0.1.0, which depends on
      RealmSwift (= 3.15.0)

Configure realm class prefix

Thank you for your awesome Lib ! really nice to use.

I have a question: is there a way to change the realmClassPrefix set at "RLM" in RealmableBase ?

I'm using a full-sync read-only Realm and cannot change the classe name: "myClasse". So I would Like to set the realmClassPrefix to ""

I've tried:

extension MyClasse: Realmable {
    static func className() -> String { "myClasse" }
}

But It doesn't seam to affect the classe name.

I've also tried:

extension MyClasse: Realmable {
   static var realmClassPrefix: String { "My" }
}

But it seam to crash my app :/

Question: Does Unrealm support Realm objects with optional properties?

Question: Does Unrealm support Realm objects with optional properties?
e.g.
struct Jukugo: Realmable {
public let id: Int? = 0
public let nameString: String? = ""
public let address: String? = ""
public let pinCode: Int? = 0

static func primaryKey() -> String?
{
return "id"
}
}

Unrealm pod for Xcode11 Beta 5

Hello,

I try to install Unrealm in Xcode11 Beta 5. When I try to instanciate Realm() it throws me an error : Terminating app due to uncaught exception 'RLMException', reason: 'Primary key property 'name' does not exist on object 'RealmSwiftClassPermission''

I saw that is because Realm and RealmSwift has to be explicitly add to Podfile to target Xcode11.

Podfile :

pod 'Unrealm'
pod 'Realm', git: 'https://github.com/realm/realm-cocoa.git', branch: 'tg/xcode-11-b1', submodules: true

pod 'RealmSwift', git: 'https://github.com/realm/realm-cocoa.git', branch: 'tg/xcode-11-b1', submodules: true

But now I got the following error : Unrealm was resolved to 0.1.0, which depends on
RealmSwift (= 3.15.0) was resolved to 3.15.0, which depends on
Realm (= 3.15.0)

I think it's because Unrealm pod doesn't support Xcode11. Is that correct ?

Problem with compaction

Hello,

I'm trying to make a Realm Compaction (will be triggered once in a while in RELEASE app), but somehow, using Unrealm prevents such a thing.

I'm trying to make the compaction has soon as the app has launched, but a thread has already opened a Realm instance.

If I try to make the compaction without registering Realmable, it doesn't work (as expected), but if I register them correctly, they open a Realm instance on the DB and can't compact it anymore.

What's the best way to handle this case ?

Thank you !

Optional Enum Problem

Hey @arturdev

I found this library and it's awesome! But I found a small issue (I think ๐Ÿ˜…).

I am having this enum and I registerd it inside AppDelegate

enum AgeRange: String, Codable, RealmableEnumString {
    case KID = "13-15"
    case TEENAGER = "16-18"
    case YOUNG_ADULT = "19-25"
    case LATE_TWENTIES = "26-30"
    case THIRTIES = "31-40"
    case MIDDLE_AGED = "41-60"
    case SENIOR = "60+"
}

And this class which is using the enum. (also registered)

final class PatientModel: Codable, Realmable {
    var uuid: String = ""
    var firstName: String?
    var lastName: String?
    var ageRange: AgeRange?
}

And I am getting this error at the build time

*** Terminating app due to uncaught exception 'RLMException', reason: 'Property 'ageRange' is declared as 'AgeRange', which is not a supported RLMObject property type. All properties must be primitives, NSString, NSDate, NSData, NSNumber, RLMArray, RLMLinkingObjects, or subclasses of RLMObject. See https://realm.io/docs/objc/latest/api/Classes/RLMObject.html for more information.'

It's a little bit strange because if I declare it as var ageRange: AgeRange (without optional) or var ageRange: [AgeRange]? = nil everything it's working.

I found a workaround by encoding and decoding manually, but it's a lot of work because I have many other fields inside PatientModel and it's a little bit annoying to write them again and again.

if let range = try container.decodeIfPresent(AgeRange.self, forKey: .ageRange) {
    self.ageRange = range
} else {
    self.ageRange = .KID
}

Am I missing something?

Thanks ๐Ÿ˜

Problem with NSKeyedArchiver

Hi,

I'm trying to save a simple model to the Realm, but somehow, the new version using NsKeyedArchiver is throwing an exception.

Error Domain=NSCocoaErrorDomain Code=4866 "The data couldnโ€™t be written because it isnโ€™t in the correct format." UserInfo={NSUnderlyingError=0x60000168e8e0 {Error Domain=NSCocoaErrorDomain Code=4864 "This decoder will only decode classes that adopt NSSecureCoding. Class '__SwiftValue' does not adopt it." UserInfo={NSDebugDescription=This decoder will only decode classes that adopt NSSecureCoding. Class '__SwiftValue' does not adopt it.}}}

Here's and exemple of the model I'm trying to save.

`struct Model: Realmable, Codable {

var id: String = UUID().uuidString
var name: String = ""
var cat: String = "default"

var type: String = "user"

var dictionary: [Int: [SomeArray]] = [:]

var startDate: Date?
var endDate: Date?

static func primaryKey() -> String? {
    return "id"
}

}`

It will save the model, but the dictionary variable will be nil.

I'm stuck there, I have tried many different solution but I won't work.

Thanks !

SPM branch behind master

The SPM branch seems behind the master one and only supports Realm 4.X instead of Realm 5.X. Is it normal ?

LinkingObjects support?

Is there a way to use LinkingObjects?

LinkingObjects expects an Object type.

Happy to help implement this, I imagine it would require wrapping LinkingObjects to be compatible with Realmable instead of Object.

Realmable migration?

Is there any migration mechanism similar to Realm's one (or any at all) ? If so, how do I use it?

Properties don't save to realm

Hi just found this and it's so nice to have the ability to use swift types instead of realm types! Keep up the good job!

I have a question about some types of properties that i'm not sure if they are supported or not but i saw one of them in your User object example so i thought maybe they would be. When I init the struct and print it out, I can see all those values. After i save them into realm and retrieve them the optional dictionary and array of enum shows up nil but the array of enum and dictionary that was inited to an empty value displays the correct value.

Optional Array of Enum
Optional Dictionary of String: String
Optional Enum = Crashes on build

Are those types above supported an i'm doing something wrong or are they not supported?

This is the testing struct I'm testing with:
Screen Shot 2021-01-13 at 11 23 28 AM

The Init:
Screen Shot 2021-01-13 at 11 23 37 AM

Wrong extraction of some properties

Was testing simple struct:

struct Foo: Realmable {
    
    let id: Int
    let name: String
    let readOnly: Bool
    let enabled: Bool
    
    static func primaryKey() -> String? {
        return "id"
    }
    
    init(id: Int, name: String, readOnly: Bool, enabled: Bool) {
        self.id = id
        self.name = name
        self.readOnly = readOnly
        self.enabled = enabled
    }
    
    init() {
        self.init(id: -1, name: "", readOnly: true, enabled: false)
    }
}

like this:

guard let realm = try? Realm() else { return }
let foo = Foo(id: 0, name: "test name", readOnly: false, enabled: true)
try? realm.write {
    realm.add(foo)
}
let foos = realm.objects(Foo.self).map({ $0 })

Found out problem with extracting properties with 0 or false value. Problem appears at this func:

Screenshot 2020-07-08 at 17 40 41

guard let value = obj.value(forKey: propertyName) fails for such properties and they left default:

Screenshot 2020-07-08 at 17 37 53

Need to add linter to the project

Need to add linter to a project for making easier the support from other people. Also, the source code has inconsistent indents, for example: 1st, 2nd

there are a few other places with issues through application code.

Performance considerations

Hello,
the tool looks good, we were doing the transition manually (from Realms Object subclasses to Swifts structs).

But I see you are using reflection in your implementation which can cause some performance issues. I did not notice any cache for the reflection so my guess would be it might perform poorly for larger requests.

I was thinking of doing some sort of similar thing, but using Codable.

__nilProperties

Hello. I'm curious why was this code below added? I reinstalled my app and it worked but just curious why I have this in my database now. It's just an empty array so not sure what it's for.

addPropertyToClassIfNeeded(className: className, name: "__nilProperties", typeStr: "Array<String>")

Installing as a SwiftPackage fails

Tried Installing by adding this line:
.package(url: "https://github.com/arturdev/Unrealm", from: "1.0.1")

or this (since the line above does not use the latest version that includes Realm 4.3.0)

.package(url: "https://github.com/arturdev/Unrealm", .branch("master"))

image

Xcode 11 compatibility issue

Hello,

First, thanks for the awesome library, very benefitting in use!

Xcode 11 has been crashing with:
Primary key property 'name' does not exist on object 'RealmSwiftPermissionRole'

It's a known issue that Realm fixed in their latest version 3.18.0. If you could update this library accordingly, that'd be great as I can't run my project until then.

Best,
-Sami

Can't install

[!] CocoaPods could not find compatible versions for pod "RealmSwift":
  In snapshot (Podfile.lock):
    RealmSwift (= 4.1.1)

  In Podfile:
    RealmSwift

    Unrealm was resolved to 0.1.0, which depends on
      RealmSwift (= 3.15.0)

How to store bulk data in realm

I am getting error while storing data using List() and [Object] in realm.

Struct object getting below error:
Screen Shot 2020-10-30 at 7 51 01 AM

While storing array [Object] getting below error:
Screen Shot 2020-10-30 at 7 49 59 AM

Is there any other way to store bulk data at a time using Unrealm?

Thanks!

How to save `Enum` type ?

Terminating app due to uncaught exception 'RLMException', reason: 'Can't persist property 'type' with incompatible type. Add to Object.ignoredProperties() class method to ignore.'
*** First throw call stack:

How to deal with this crash?

I have an app crashing every time when I'm trying to save one data type. I have no problems with others. Is there a way to find out what is causing it and how to change my data struct to fix it?

Here's a crash log:

2019-10-31 20:21:14.672690+0200 App Name[48103:1190682] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<RLM:Unmanaged RLMProductFields 0x600002307d90> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key description.'
*** First throw call stack:
(
	0   CoreFoundation                      0x00007fff23baa1ee __exceptionPreprocess + 350
	1   libobjc.A.dylib                     0x00007fff50864b20 objc_exception_throw + 48
	2   CoreFoundation                      0x00007fff23ba9db9 -[NSException raise] + 9
	3   Realm                               0x000000010759394c -[RLMObjectBase setValue:forUndefinedKey:] + 1100
	4   Foundation                          0x00007fff2563e130 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 325
	5   Unrealm                             0x0000000108fa85a2 $s7Unrealm7convert33_C4ACF08D0134400842049C7DF7DCE9DDLL3val2toyXlSgyp_xmtSo8NSObjectCRbzlFySSSg5label_yp5valuet_tXEfU0_ + 7570
	6   Unrealm                             0x0000000108faa19b $sSSSgyps5Error_pIggnzo_AA5label_yp5valuetsAB_pIegnzo_TR + 59
	7   Unrealm                             0x0000000108fab1c4 $sSSSgyps5Error_pIggnzo_AA5label_yp5valuetsAB_pIegnzo_TRTA + 20
	8   libswiftCore.dylib                  0x00007fff50e6b024 $sSTsE7forEachyyy7ElementQzKXEKF + 452
	9   Unrealm                             0x0000000108fa2052 $s7Unrealm7convert33_C4ACF08D0134400842049C7DF7DCE9DDLL3val2toyXlSgyp_xmtSo8NSObjectCRbzlF + 658
	10  Unrealm                             0x0000000108fa75a8 $s7Unrealm7convert33_C4ACF08D0134400842049C7DF7DCE9DDLL3val2toyXlSgyp_xmtSo8NSObjectCRbzlFySSSg5label_yp5valuet_tXEfU0_ + 3480
	11  Unrealm                             0x0000000108faa19b $sSSSgyps5Error_pIggnzo_AA5label_yp5valuetsAB_pIegnzo_TR + 59
	12  Unrealm                             0x0000000108fab1c4 $sSSSgyps5Error_pIggnzo_AA5label_yp5valuetsAB_pIegnzo_TRTA + 20
	13  libswiftCore.dylib                  0x00007fff50e6b024 $sSTsE7forEachyyy7ElementQzKXEKF + 452
	14  Unrealm                             0x0000000108fa2052 $s7Unrealm7convert33_C4ACF08D0134400842049C7DF7DCE9DDLL3val2toyXlSgyp_xmtSo8NSObjectCRbzlF + 658
	15  Unrealm                             0x0000000108fa1cb7 $s7Unrealm9RealmablePAAE8toObject10RealmSwift0D0CSgyF + 247
	16  App Name                            0x0000000105708197 $s18App_Name7ProductV7Unrealm13RealmableBaseAadEP8toObject10RealmSwift0H0CSgyFTW + 39
	17  Unrealm                             0x0000000108f9295d $s10RealmSwift0A0C7UnrealmE3add_6updateyx_AC12UpdatePolicyOtAD9RealmableRzlF + 189
	18  Unrealm                             0x0000000108f92e0b $s10RealmSwift0A0C7UnrealmE3add_6updateyx_SbtSTRzAD9Realmable7ElementRpzlF + 715
	19  App Name                            0x0000000105a6a489 $s18App_Name14ProductFetcherC5cache33_7573542C37BF51E4E44F88A166B84251LLyySayAA0C0VGFyyXEfU_ + 105
	20  RealmSwift                          0x0000000108db4b63 $s10RealmSwift0A0C5writeyyyyKXEKF + 83
	21  App Name                            0x0000000105a6a043 $s18App_Name14ProductFetcherC5cache33_7573542C37BF51E4E44F88A166B84251LLyySayAA0C0VGF + 291
...

The function where it crashes:

	private func cache(_ products: [ProductFields]) {
		let realm = try! Realm()
		do {
			try realm.write {
				realm.add(products, update: true)
			}
		} catch {
			print("Failed to cache ProductFields. \(error.localizedDescription)")
		}
	}

Here's a struct:

struct ProductFields: Codable, Identifiable, Hashable, Realmable {
	var id: String = ""
	var name: String = ""
	var category: [String] = []
	var categoryName: [String] = []
	var categoryIconTypeRaw: [String] = []
	var description: String? = nil
	var duration: Double? = nil
	var guideSpeaks: [String]? = nil
	var included: [String]? = nil
	var availability: String? = nil
	var shortDescription: String? = nil
	var maxNumberOfParticipants: Int? = nil
	var isOfferedInHotelOptional: Bool? = nil
	var reservationNotes: String? = nil
	var priceIsFixedOptional: Bool? = nil
	var price: Double? = nil
	var pricePer: String? = nil
	var currency: String? = nil
	var ctaTextRaw: String? = nil
	var ctaLink: String? = nil
	var mainImage: [AppImage] = [] // <-- AppImage is also Realmable, and it works well embedded in other structs

	enum CodingKeys: String, CodingKey {
		case name = "Name"
		case category = "Category"
		case categoryName = "Category Name"
		case categoryIconTypeRaw = "Category Icon Type"
		case description = "Description"
		case duration = "Duration"
		case guideSpeaks = "Guide Speaks"
		case included = "Included"
		case availability = "Availability"
		case shortDescription = "Short Description"
		case maxNumberOfParticipants = "Max Number of Participants"
		case isOfferedInHotelOptional = "Is Offered in Hotel"
		case reservationNotes = "Reservation Notes"
		case priceIsFixedOptional = "Price is Fixed"
		case price = "Price"
		case pricePer = "Price Per"
		case currency = "Currency"
		case ctaTextRaw = "CTA Text"
		case ctaLink = "CTA Link"
		case id = "Record ID"
		case mainImage = "Main Image"
	}
	
	// A set of calculated properties, I've added them all to ignoredProperties below
	var categories {...}
	var numberOfParticipantsFormatted {...}
	var durationFormatted {...}
	var ctaText {...}
	var ctaURL {...}
	var categoryType {...}
	var isOfferedInHotel {...}
	var priceIsFixed {...}
	var priceString {...}
	var priceFullString {...}
	
	static func primaryKey() -> String? { "id" }
	static func ignoredProperties() -> [String] {
		[
			"priceString",
			"priceFullString",
			"priceIsFixed",
			"isOfferedInHotel",
			"categories",
			"categoryType",
			"ctaText",
			"ctaURL",
			"durationFormatted",
			"numberOfParticipantsFormatted"
		]
	}
}

I have all needed classes initialised in didFinishLaunchingWithOptions:

		Realm.registerRealmables(
			...
			AppImage.self,
			ProductFields.self
		)

CGFloat, CGPoint, CGSize.. tuples ?

Hey there,

I am trying to have a simple struct to be Realmable...

struct Sprite: Realmable {
    let id: String
    let position: CGPoint
    let size: CGSize
    let alpha: CGFloat
  
    static fun primaryKey() -> String { "id" }
}

I am adding extension RealmableEnum on each of these, matching Float, tried with NSNumber(cgPoint: ) and with NSCoder.string(cgPoint:).. is there a way to do so ?

Or should I basically just save JSON strings for each object, generated by Codable ?.. sounds less efficient to me

Observing a Realm object?

Hey @arturdev

This seems like an amazing library. However, one useful paradigm we use (with RxRealm) is the ability to observe changes on an object in the realm db and register a callback.

This function is the public func observe<T>(on queue: DispatchQueue? = nil, _ block: @escaping (RealmSwift.ObjectChange<T>) -> Void) -> RealmSwift.NotificationToken where T : RealmSwift.Object.

Does the fact that the objects are no longer "live" make this no longer possible?

How to fetch swift dictionary stored in realm ?

I have this field in a struct Contact.

var customFields: [String: String?]?

I'm able to store this field in realm. It is storing as data field.

But when I try to fetch the contact and read it, the custom fields are empty.

Do I have to manually convert data. back into swift dicionary ?

At which level, do I have to do this conversion ?

Info:

At the line:

  let results = self.objects(cls)

when I do, po results.first, I can see the customField with some data in it.

customFields = <length = 24, bytes = 0x62706c6973743030d4010203040506070a58247665727369 โ€” 1537 total bytes>;

Now after Results(rlmResult: results) happens,

the struct shows customFields as nil.

Not sure how I intercept and do the conversion of data to dictionary.

Update:

Able to get it by tweaking a part of the code.

if let data = value as? Data { 

   //works
if let json = try NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(data) {
                                   try property.set(value: json, on: &self)
                               }

}

For some reason child.value is [AnyHashable:Any] is nil and this condition fails .

Performance issue

I have hit a performance issue with Unrealm. My Structure is:

Stint (1 instance only):
- Has 8 Lap relations (one to many)
- Lap has 3k - 6k location objects (one to many)

When I do something simple like:
` let stints = realm.objects(Stint.self)

    for stint in stints{
        if(stint.laps.count>0){
            allStints.append(stint)
        }
    }

`
It takes 2s to go through this for loop.

What is the best approach you suggest for optimizing this?

Does Unrealm support associated values Enum ?

I have problem with my struct model, it's generate from google protobuf and has an enum look like this:
enum OneOf_Doc: Equatable {
case art(My_Model)
...
}
With normal enum i can make it RealmableEnum but not to this type.
How do u guys deal with this ? Thanks

enums with associated values

Hi I have this enum with associated types

enum LogValue: Codable, RealmableEnum {
    case sugar(SugarLogCreate)
    case carb(CarbLog)
    case weight(WeightLog)

    init(from decoder: Decoder) throws {
        let container = try decoder.singleValueContainer()
        if let x = try? container.decode(SugarLogCreate.self) {
            self = .sugar(x)
            return
        }
        if let x = try? container.decode(CarbLog.self) {
            self = .carb(x)
            return
        }
        if let x = try? container.decode(WeightLog.self) {
            self = .weight(x)
            return
        }
        throw DecodingError.typeMismatch(LogValue.self, DecodingError.Context(codingPath: decoder.codingPath, debugDescription: "Wrong type for Log Value"))
    }
    
   func encode(to encoder: Encoder) throws {
        var container = encoder.singleValueContainer()
        switch self {
        case .sugar(let x):
            try container.encode(x)
        case .carb(let x):
            try container.encode(x)
        case .weight(let x):
            try container.encode(x)
        }
    }
}

where each SugarLogCreate, CarbLog and WeightLog are structs conforming toRealmable

I get this error that tells me I have not conformed to RealmableEnums
"Type 'LogValue' does not conform to protocol 'RealmableEnum'"
and makes me put these methods in my code which I have no idea what to do with them:

func rlmValue() -> Any {
        <#code#>
    }
    
    init?(rlmValue: Any) {
        <#code#>
    }
    
    static var rawValueType: Any.Type
    

What should I do in this case?
Thank you in advance for your reply.

Unit Test Target Crash

Hi!

I'm getting a crash in my unit test target, in Realm.registerRealmables(...) -- it loads my AppDelegate, which calls the former method.

Specifically, I am getting an EXC_BAD_ACCESS on line 53 of NominalMetadataType.swift.

More specifically, numberOfFields() is what is crashing. The field is an empty [String]

Problem with JSONSerialization with Int as key

Hello,
I'm migrating my Object models to Realmable, but I have a problem with a data type I'm trying to save.

I have a data model defined like this :

` struct WorkoutRoutine: Realmable, Codable {

var id: String = UUID().uuidString
var name: String = ""
var bodyPart: String = ""

var type: String = "normal"
var globalRestTimer: Double = 0.0
var exerciseSpecificRestTimer: [Int: Double] = [0: 0.0]

var exercises: [Exercise]?
var exercisesTargetSets: [Int: Int] = [0:0]
var exercisesTargetReps: [Int: Int] = [0:0]

var createdAt: Date = Date()

static func primaryKey() -> String? {
    return "id"

}

}`

It crashes when it's trying to serialize my object as JSON. I think it's due to the fact that the keys are required to be of type NSString (when serializing with JSONSerialization), and I'm using "Int". How could they be converted automatically?

I'm not sure how to convert it to a string. When I take my model and encode it using JSONEncoder, it produces valid JSON.

Here are some screenshot of the Exception Breakpoint:

Screen Shot 2020-02-01 at 3 40 21 PM
Screen Shot 2020-02-01 at 3 40 21 PM
Screen Shot 2020-02-01 at 3 44 38 PM

Save swift array of custom object

I can not save a Swift array of custom objects.
Terminating app due to uncaught exception 'RLMException', reason: 'Property 'weather' is of type 'RLMArray<RLMWeather>' which is not a supported RLMArray object type. RLMArrays can only contain instances of RLMObject subclasses. See https://realm.io/docs/objc/latest/#to-many for more information.'
Here are my data models

struct CurrentWeather: Codable, Realmable {
    var coord: Coord?; var weather: [Weather]?
    var main: Main?; var clouds: Clouds?
    var visibility, id, dt: Int?;var wind: Wind?
    var sys: Sys?; var name: String?
}

extension CurrentWeather {
    func currentTemp() -> String { main?.temp?.format() ?? "" }
    func icon() -> String { (weather?[0].icon ?? "").systemIconName() }
    func loaction() -> String { "\(name ?? "") โ€ข \(sys?.country ?? "")" }
    func desc() -> String { weather?[0].weatherDescription ?? "" }
}

// MARK: - Clouds
struct Clouds: Codable, Realmable {
    var all: Int?
}

// MARK: - Coord
struct Coord: Codable, Realmable {
    var lat, lon: Double?
}

// MARK: - Main
struct Main: Codable, Realmable {
    var temp: Double?
    var pressure, humidity: Int?
    var tempMin, tempMax: Double?

    enum CodingKeys: String, CodingKey {
        case temp, pressure, humidity
        case tempMin = "temp_min"
        case tempMax = "temp_max"
    }
}

// MARK: - Sys
struct Sys: Codable, Realmable {
    var country: String?
    var sunrise, sunset: Int?
}

// MARK: - Weather
struct Weather: Codable, Realmable {
    var id: Int?
    var main, weatherDescription, icon: String?

    enum CodingKeys: String, CodingKey {
        case id, main
        case weatherDescription = "description"
        case icon
    }
}

// MARK: - Wind
struct Wind: Codable, Realmable {
    var speed: Double?
    var deg: Int?
}

Thanks for help!

Realm program crashes while opening realm database

program crashes when trying to open realm database.

		let config = Realm.Configuration(fileURL: destinationURL,
										 readOnly: false,
										 schemaVersion: 1,
										 migrationBlock: { (migration, oldSchemaVersion) in
											if (oldSchemaVersion < 1) {

											}
		})
		let realm: Realm = {
			return try! Realm(configuration: config)
		}()

_The debugger gives me a hint that it is in the object table Kanji and near column kunYomis_

struct Kanji: Realmable {
  var id: Int = 0
  var kanjiCharacter: String = ""
  var hexUnicode: String = ""
  var frequency: Int = 0
  var jlptLevel: Int = 0
  var gradeJA: Int = 0
  var strokeCount:Int = 0
  var classification: String = ""
  var kunYomis = [String]()
  var onYomis = [String]()
  var longMeanings = [String]()
  var shortMeanings = [String]()
  var radicalComponentCount: Int = 0
  var radicalComponentStrings = [String]()
  static func primaryKey() -> String?
  {
    return "id"
  }

}

This is the definition of the database as shown by RealmStudio when generating Swift model definition

class RLMKanji: Object {
    @objc dynamic var id: Int = 0
    @objc dynamic var kanjiCharacter: String = ""
    @objc dynamic var hexUnicode: String = ""
    @objc dynamic var frequency: Int = 0
    @objc dynamic var jlptLevel: Int = 0
    @objc dynamic var gradeJA: Int = 0
    @objc dynamic var strokeCount: Int = 0
    @objc dynamic var classification: String = ""
    let kunYomis = List<String>()
    let onYomis = List<String>()
    let longMeanings = List<String>()
    let shortMeanings = List<String>()
    @objc dynamic var radicalComponentCount: Int = 0
    let radicalComponentStrings = List<String>()

    override static func primaryKey() -> String? {
        return "id"
    }
}

Have been at it since yesterday, couldn't figure out what could be wrong.
Able to open the database with RealmStudio and all the data appears correct.
I'm assuming that this is not a problem with Realm itself but in my definitions but can't figure out. There are three other objects in the database as well.

.../Library/Developer/Xcode/DerivedData/JukugoExample-dswqnefsbrxzlpehxzpaxosvetds/SourcePackages/checkouts/realm-core/src/realm/table.cpp:3050: [realm-core-5.23.8] Assertion failed: get_real_column_type(col_ndx) == col_type_String || get_real_column_type(col_ndx) == col_type_StringEnum [5, 2, 5, 3]
0 JukugoExample 0x0000000106db041f _ZN5realm4utilL18terminate_internalERNSt3__118basic_stringstreamIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE + 31
1 JukugoExample 0x0000000106db06d3 _ZN5realm4util9terminateEPKcS2_lOSt16initializer_listINS0_9PrintableEE + 243
2 JukugoExample 0x0000000106d1fac0 ZN5realm4util9terminateIJNS_10ColumnTypeES2_S2_S2_EEEvPKcS4_lDpT + 240
3 JukugoExample 0x0000000106d1f890 _ZNK5realm5Table3getINS_10StringDataEEET_mm + 320
4 JukugoExample 0x0000000106652aa5 _ZNK5realm5Table10get_stringEmm + 37
5 JukugoExample 0x000000010665fc38 _ZZN12_GLOBAL__N_120copy_property_valuesERKN5realm8PropertyERNS0_5TableEENK3$0clIMS4_KFNS0_10StringDataEmmEMS4_FvmmS8_bEEEDaT_T0 + 408
6 JukugoExample 0x000000010665efa5 _ZN12_GLOBAL__N_120copy_property_valuesERKN5realm8PropertyERNS0_5TableE + 501
7 JukugoExample 0x0000000106656f14 _ZN12_GLOBAL__N_122make_property_optionalERN5realm5GroupERNS0_5TableENS0_8PropertyE + 84
8 JukugoExample 0x000000010665dbd0 _ZZL27apply_pre_migration_changesRN5realm5GroupERKNSt3__16vectorINS_12SchemaChangeENS2_9allocatorIS4_EEEEEN7ApplierclENS_13schema_change20MakePropertyNullableE + 112
9 JukugoExample 0x000000010665d89f ZNK5realm12SchemaChange5visitIRZL27apply_pre_migration_changesRNS_5GroupERKNSt3__16vectorIS0_NS4_9allocatorIS0_EEEEE7ApplierEEDaOT + 367
10 JukugoExample 0x0000000106654bc3 _ZL27apply_pre_migration_changesRN5realm5GroupERKNSt3__16vectorINS_12SchemaChangeENS2_9allocatorIS4_EEEE + 115
11 JukugoExample 0x0000000106654322 _ZN5realm11ObjectStore20apply_schema_changesERNS_5GroupEyRNS_6SchemaEyNS_10SchemaModeERKNSt3__16vectorINS_12SchemaChangeENS6_9allocatorIS8_EEEENS_4util8OptionalINS6_12basic_stringIcNS6_11char_traitsIcEENS9_IcEEEEEENS6_8functionIFvvEEE + 626
12 JukugoExample 0x000000010668f679 ZN5realm5Realm13update_schemaENS_6SchemaEyNSt3__18functionIFvNS2_10shared_ptrIS0_EES5_RS1_EEENS3_IFvS5_EEEb + 1385
13 JukugoExample 0x00000001067d61fd +[RLMRealm realmWithConfiguration:error:] + 3469
14 JukugoExample 0x0000000106e02ce0 $sSo8RLMRealmC13configurationABSo0A13ConfigurationC_tKcfCTO + 144
15 JukugoExample 0x0000000106e02ede $s10RealmSwift0A0V13configurationA2C13ConfigurationV_tKcfC + 94
16 JukugoExample 0x00000001065590ef $s13JukugoExample11AppDelegateC18initializeDatabaseyyF10RealmSwift0G0VyXEfU0
+ 63
17 JukugoExample 0x000000010655899a $s13JukugoExample11AppDelegateC18initializeDatabaseyyF + 1114
18 JukugoExample 0x0000000106557ef7 $s13JukugoExample11AppDelegateC11application_29didFinishLaunchingWithOptionsSbSo13UIApplicationC_SDySo0k6LaunchJ3KeyaypGSgtF + 103
19 JukugoExample 0x0000000106557fe3 $s13JukugoExample11AppDelegateC11application_29didFinishLaunchingWithOptionsSbSo13UIApplicationC_SDySo0k6LaunchJ3KeyaypGSgtFTo + 211
20 UIKitCore 0x00007fff48c0fecc -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 232
21 UIKitCore 0x00007fff48c1186b -[UIApplication _callInitializationDelegatesWithActions:forCanvas:payload:fromOriginatingProcess:] + 3985
22 UIKitCore 0x00007fff48c1742d -[UIApplication _runWithMainScene:transitionContext:completion:] + 1226
23 UIKitCore 0x00007fff48322a9a -[_UISceneLifecycleMultiplexer completeApplicationLaunchWithFBSScene:transitionContext:] + 179
24 UIKitCore 0x00007fff48c1391b -[UIApplication _compellApplicationLaunchToCompleteUnconditionally] + 59
25 UIKitCore 0x00007fff48c13c1a -[UIApplication _run] + 754
26 UIKitCore 0x00007fff48c19220 UIApplicationMain + 1605
27 JukugoExample 0x000000010655a0fb main + 75
28 libdyld.dylib 0x00007fff519b910d start + 1
29 ??? 0x0000000000000001 0x0 + 1!!! IMPORTANT: Please send this log and info about Realm SDK version and other relevant reproduction info to [email protected] 15:46:54.297867+0530 JukugoExample[6741:129825] .../Library/Developer/Xcode/DerivedData/JukugoExample-dswqnefsbrxzlpehxzpaxosvetds/SourcePackages/checkouts/realm-core/src/realm/table.cpp:3050: [realm-core-5.23.8] Assertion failed: get_real_column_type(col_ndx) == col_type_String || get_real_column_type(col_ndx) == col_type_StringEnum [5, 2, 5, 3]
0 JukugoExample 0x0000000106db041f _ZN5realm4utilL18terminate_internalERNSt3__118basic_stringstreamIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE + 31
1 JukugoExample 0x0000000106db06d3 _ZN5realm4util9terminateEPKcS2_lOSt16initializer_listINS0_9PrintableEE + 243
2 JukugoExample 0x0000000106d1fac0 ZN5realm4util9terminateIJNS_10ColumnTypeES2_S2_S2_EEEvPKcS4_lDpT + 240
3 JukugoExample 0x0000000106d1f890 _ZNK5realm5Table3getINS_10StringDataEEET_mm + 320
4 JukugoExample 0x0000000106652aa5 _ZNK5realm5Table10get_stringEmm + 37
5 JukugoExample 0x000000010665fc38 _ZZN12_GLOBAL__N_120copy_property_valuesERKN5realm8PropertyERNS0_5TableEENK3$0clIMS4_KFNS0_10StringDataEmmEMS4_FvmmS8_bEEEDaT_T0 + 408
6 JukugoExample 0x000000010665efa5 _ZN12_GLOBAL__N_120copy_property_valuesERKN5realm8PropertyERNS0_5TableE + 501
7 JukugoExample 0x0000000106656f14 _ZN12_GLOBAL__N_122make_property_optionalERN5realm5GroupERNS0_5TableENS0_8PropertyE + 84
8 JukugoExample 0x000000010665dbd0 _ZZL27apply_pre_migration_changesRN5realm5GroupERKNSt3__16vectorINS_12SchemaChangeENS2_9allocatorIS4_EEEEEN7ApplierclENS_13schema_change20MakePropertyNullableE + 112
9 JukugoExample 0x000000010665d89f ZNK5realm12SchemaChange5visitIRZL27apply_pre_migration_changesRNS_5GroupERKNSt3__16vectorIS0_NS4_9allocatorIS0_EEEEE7ApplierEEDaOT + 367
10 JukugoExample 0x0000000106654bc3 _ZL27apply_pre_migration_changesRN5realm5GroupERKNSt3__16vectorINS_12SchemaChangeENS2_9allocatorIS4_EEEE + 115
11 JukugoExample 0x0000000106654322 _ZN5realm11ObjectStore20apply_schema_changesERNS_5GroupEyRNS_6SchemaEyNS_10SchemaModeERKNSt3__16vectorINS_12SchemaChangeENS6_9allocatorIS8_EEEENS_4util8OptionalINS6_12basic_stringIcNS6_11char_traitsIcEENS9_IcEEEEEENS6_8functionIFvvEEE + 626
12 JukugoExample 0x000000010668f679 ZN5realm5Realm13update_schemaENS_6SchemaEyNSt3__18functionIFvNS2_10shared_ptrIS0_EES5_RS1_EEENS3_IFvS5_EEEb + 1385
13 JukugoExample 0x00000001067d61fd +[RLMRealm realmWithConfiguration:error:] + 3469
14 JukugoExample 0x0000000106e02ce0 $sSo8RLMRealmC13configurationABSo0A13ConfigurationC_tKcfCTO + 144
15 JukugoExample 0x0000000106e02ede $s10RealmSwift0A0V13configurationA2C13ConfigurationV_tKcfC + 94
16 JukugoExample 0x00000001065590ef $s13JukugoExample11AppDelegateC18initializeDatabaseyyF10RealmSwift0G0VyXEfU0
+ 63
17 JukugoExample 0x000000010655899a $s13JukugoExample11AppDelegateC18initializeDatabaseyyF + 1114
18 JukugoExample 0x0000000106557ef7 $s13JukugoExample11AppDelegateC11application_29didFinishLaunchingWithOptionsSbSo13UIApplicationC_SDySo0k6LaunchJ3KeyaypGSgtF + 103
19 JukugoExample 0x0000000106557fe3 $s13JukugoExample11AppDelegateC11application_29didFinishLaunchingWithOptionsSbSo13UIApplicationC_SDySo0k6LaunchJ3KeyaypGSgtFTo + 211
20 UIKitCore 0x00007fff48c0fecc -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 232
21 UIKitCore 0x00007fff48c1186b -[UIApplication _callInitializationDelegatesWithActions:forCanvas:payload:fromOriginatingProcess:] + 3985
22 UIKitCore 0x00007fff48c1742d -[UIApplication _runWithMainScene:transitionContext:completion:] + 1226
23 UIKitCore 0x00007fff48322a9a -[_UISceneLifecycleMultiplexer completeApplicationLaunchWithFBSScene:transitionContext:] + 179
24 UIKitCore 0x00007fff48c1391b -[UIApplication _compellApplicationLaunchToCompleteUnconditionally] + 59
25 UIKitCore 0x00007fff48c13c1a -[UIApplication _run] + 754
26 UIKitCore 0x00007fff48c19220 UIApplicationMain + 1605
27 JukugoExample 0x000000010655a0fb main + 75
28 libdyld.dylib 0x00007fff519b910d start + 1
29 ??? 0x0000000000000001 0x0 + 1!!! IMPORTANT: Please send this log and info about Realm SDK version and other relevant reproduction info to [email protected].
(lldb)
Screenshot 2020-05-17 at 15 58 34

Is it possible to save a swift array of enums?

I'm getting this error

Terminating app due to uncaught exception 'RLMException', reason: 'Property 'actions' is of type 'RLMArray' which is not a supported RLMArray object type. RLMArrays can only contain instances of RLMObject subclasses. See https://realm.io/docs/objc/latest/#to-many for more information.'

my property actions is defined as this:

var actions: [Action] = []

in a Realmable struct. Action is an enum that conforms to RealmableEnum

Any ideas?

enums not working

i try to use enum inside an object and it's returning the following error

Terminating app due to uncaught exception 'RLMException', reason: 'Property 'type' is declared as 'RLMnone', which is not a supported RLMObject property type. All properties must be primitives, NSString, NSDate, NSData, NSNumber, RLMArray, RLMLinkingObjects, or subclasses of RLMObject. See https://realm.io/docs/objc/latest/api/Classes/RLMObject.html for more information.'

error STACK:

(
0 CoreFoundation 0x00007fff23c4f02e __exceptionPreprocess + 350
1 libobjc.A.dylib 0x00007fff50b97b20 objc_exception_throw + 48
2 Realm 0x0000000110d97ff1 -[RLMProperty setTypeFromRawType:] + 2673
3 Realm 0x0000000110d99101 -[RLMProperty initSwiftPropertyWithName:indexed:linkPropertyDescriptor:property:instance:] + 2673
4 Realm 0x0000000110d6f3ba +[RLMObjectSchema propertiesForClass:isSwift:] + 1594
5 Realm 0x0000000110d6d43e +[RLMObjectSchema schemaForObjectClass:] + 942
6 Realm 0x0000000110e99c4e _ZL16RLMRegisterClassP10objc_class + 302
7 Realm 0x0000000110e9ac7d __25+[RLMSchema sharedSchema]_block_invoke + 77
8 CoreFoundation 0x00007fff23cd7c37 NSDICTIONARY_IS_CALLING_OUT_TO_A_BLOCK + 7
9 CoreFoundation 0x00007fff23cb0dce -[__NSDictionaryM enumerateKeysAndObjectsWithOptions:usingBlock:] + 238
10 Realm 0x0000000110e9a9bf +[RLMSchema sharedSchema] + 479
11 Realm 0x0000000110e60fd5 +[RLMRealm realmWithConfiguration:error:] + 2805
12 RealmSwift 0x000000011251fe01 $sSo8RLMRealmC13configurationABSo0A13ConfigurationC_tKcfCTO + 145
13 RealmSwift 0x000000011251fcb5 $s10RealmSwift0A0VACyKcfC + 101
14 Dev-โ—Šรฎโ—Šรปโ—ŠรŸโ—Šยถโ—Šยขโ—Šรฏโ—Šโ€ โ—Šรดโ—Šรน 0x000000010dca85e1 $s7Pro_Dev20RealmDataBaseManagerC14saveMikiSearch04mikiI0yAA0hI0Vz_tF + 161
15 Dev-โ—Šรฎโ—Šรปโ—ŠรŸโ—Šยถโ—Šยขโ—Šรฏโ—Šโ€ โ—Šรดโ—Šรน 0x000000010d96cd7f $s7Pro_Dev22LeftMenuViewControllerC11onItemClick4itemyAA0adH0C_tF + 1359
16 Dev-โ—Šรฎโ—Šรปโ—ŠรŸโ—Šยถโ—Šยขโ—Šรฏโ—Šโ€ โ—Šรดโ—Šรน 0x000000010d9728d5 $s7Pro_Dev22LeftMenuViewControllerCAA0d5TableE8ProtocolA2aDP11onItemClick4itemyAA0adJ0C_tFTW + 37
17 Dev-โ—Šรฎโ—Šรปโ—ŠรŸโ—Šยถโ—Šยขโ—Šรฏโ—Šโ€ โ—Šรดโ—Šรน 0x000000010dfa2185 $s7Pro_Dev13MenuTableViewC05tableE0_14didSelectRowAtySo07UITableE0C_10Foundation9IndexPathVtF + 517
18 Dev-โ—Šรฎโ—Šรปโ—ŠรŸโ—Šยถโ—Šยขโ—Šรฏโ—Šโ€ โ—Šรดโ—Šรน 0x000000010dfa22c7 $s7Pro_Dev13MenuTableViewC05tableE0_14didSelectRowAtySo07UITableE0C_10Foundation9IndexPathVtFTo + 167
19 UIKitCore 0x00007fff47a37657 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:isCellMultiSelect:] + 855
20 UIKitCore 0x00007fff47a372e9 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 97
21 UIKitCore 0x00007fff47a37b14 -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 334
22 UIKitCore 0x00007fff47858d48 _runAfterCACommitDeferredBlocks + 352
23 UIKitCore 0x00007fff478494ec _cleanUpAfterCAFlushAndRunDeferredBlocks + 248
24 UIKitCore 0x00007fff47879365 _afterCACommitHandler + 85
25 CoreFoundation 0x00007fff23bb1617 CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 23
26 CoreFoundation 0x00007fff23bac0ae __CFRunLoopDoObservers + 430
27 CoreFoundation 0x00007fff23bac72a __CFRunLoopRun + 1514
28 CoreFoundation 0x00007fff23babe16 CFRunLoopRunSpecific + 438
29 GraphicsServices 0x00007fff38438bb0 GSEventRunModal + 65
30 UIKitCore 0x00007fff4784fb48 UIApplicationMain + 1621
31 Dev-โ—Šรฎโ—Šรปโ—ŠรŸโ—Šยถโ—Šยขโ—Šรฏโ—Šโ€ โ—Šรดโ—Šรน 0x000000010ddebe8a main + 490
32 libdyld.dylib 0x00007fff51a1dc25 start + 1
33 ??? 0x0000000000000005 0x0 + 5
)

ENUM im trying to insert:
`

import Foundation
import Unrealm

class MikiDate : MikiDateListable, Realmable {
required init() {

}

static func == (lhs: MikiDate, rhs: MikiDate) -> Bool {
    return true
}


enum DateType: Int, Realmable {
    init() {
        self = .none
    }        
    case none = 0
    case now
    case today
    case tomorrow
    case laterDate
    case rangeDate
}

var text : String?
var checked = false
var type = DateType.none

init(type: DateType) {
    self.type = type
}

//MARK: MikiListable
func mikiText() -> String? {
    switch type {
        case .now:
            return "ืขื›ืฉื™ื• - ืฉื™ื’ื™ืข ื“ื—ื•ืฃ"
        case .today:
            return "ื”ื™ื•ื"
        case .tomorrow:
            return "ืžื—ืจ"
        case .laterDate:
            return "ืชืืจื™ืš ืื—ืจ"
        case .rangeDate:
            return "ื˜ื•ื•ื— ืชืืจื™ื›ื™ื"
        default:
            return ""
    }
}

func isChecked() -> Bool {
    return checked
}

}
`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.