Weird thing hapening while setting and getting array in swift42019 Community Moderator ElectionMemory management of container classesUpdate or reload UITableView after completion of delete action on detail viewGet URL of UIIimagePickerController by using swift4Swift Error - Use of undeclared type 'cell' - Collection ViewGetting Error while Using JSONDecodable in swift4?How to set admob on scrollView in swift4TableView Controller is hiding the dropshadow of swipemenu in swift 4facing problem with 'automaticallyMergesChangesFromParent' in parent-child context in coredata?using an array to subset an array in Swift4I'm using Alamofire, Objectmapper, Realm and everything is working beside one thing: I can't map nested objects in swift4
Sword in the Stone story where the sword was held in place by electromagnets
Good allowance savings plan?
Co-worker team leader wants to inject his friend's awful software into our development. What should I say to our common boss?
Can elves maintain concentration in a trance?
2D counterpart of std::array in C++17
How to deal with taxi scam when on vacation?
Why did it take so long to abandon sail after steamships were demonstrated?
Font with correct density?
How to answer questions about my characters?
Pinhole Camera with Instant Film
Why are the outputs of printf and std::cout different
In-house repeater?
Why do Australian milk farmers need to protest supermarkets' milk price?
Why doesn't the EU now just force the UK to choose between referendum and no-deal?
Using "wallow" verb with object
The use of "touch" and "touch on" in context
Why using two cd commands in bash script does not execute the second command
My story is written in English, but is set in my home country. What language should I use for the dialogue?
Why do passenger jet manufacturers design their planes with stall prevention systems?
Counting certain elements in lists
How to simplify this time periods definition interface?
How to deal with a cynical class?
Rejected in 4th interview round citing insufficient years of experience
What interface is this on my hard drive?
Weird thing hapening while setting and getting array in swift4
2019 Community Moderator ElectionMemory management of container classesUpdate or reload UITableView after completion of delete action on detail viewGet URL of UIIimagePickerController by using swift4Swift Error - Use of undeclared type 'cell' - Collection ViewGetting Error while Using JSONDecodable in swift4?How to set admob on scrollView in swift4TableView Controller is hiding the dropshadow of swipemenu in swift 4facing problem with 'automaticallyMergesChangesFromParent' in parent-child context in coredata?using an array to subset an array in Swift4I'm using Alamofire, Objectmapper, Realm and everything is working beside one thing: I can't map nested objects in swift4
I am using a class LocalSubject.swift which i store in a RealmDB.
class LocalSubject: Object
@objc dynamic var subjectName: String?
private var modules: [Module] = [Module]()
@objc dynamic var moduleArrayJSON: String? = nil
public func addModule(module: Module)
modules.append(module)
public func setModules(modules: [Module])
self.modules = modules
print("LocalSubject.swift > setModules() > " + String(describing: modules.count) + " > " + String(describing: self.modules.count))
public func getModules()-> [Module]
print("LocalSubject.swift > getModules() > " + String(describing: modules.count) + " > " + String(describing: self.modules.count))
return modules.sorted(by: $0.displayOrder! < $1.displayOrder!)
I store the class in DB by converting "modules" array to json & back.
In below function, "modules" is computed correctly with count = 3, then i set it in "maths" object of LocalSubject. Now when i try to get the "modules" from "maths", i am always getting an empty array.
public func createModuleArrayFromJSONInSubjects()
let modules = getModuleArrayFromJSON(moduleArrayJSON: (maths?.moduleArrayJSON)!)
for module in modules
print("-> " + module.title!)
maths?.setModules(modules: modules)
for module in (maths?.getModules())!
print("---> " + module.title!)
I am unable to figure this out, it seems weird.
Am i missing something?
ios realm swift4
add a comment |
I am using a class LocalSubject.swift which i store in a RealmDB.
class LocalSubject: Object
@objc dynamic var subjectName: String?
private var modules: [Module] = [Module]()
@objc dynamic var moduleArrayJSON: String? = nil
public func addModule(module: Module)
modules.append(module)
public func setModules(modules: [Module])
self.modules = modules
print("LocalSubject.swift > setModules() > " + String(describing: modules.count) + " > " + String(describing: self.modules.count))
public func getModules()-> [Module]
print("LocalSubject.swift > getModules() > " + String(describing: modules.count) + " > " + String(describing: self.modules.count))
return modules.sorted(by: $0.displayOrder! < $1.displayOrder!)
I store the class in DB by converting "modules" array to json & back.
In below function, "modules" is computed correctly with count = 3, then i set it in "maths" object of LocalSubject. Now when i try to get the "modules" from "maths", i am always getting an empty array.
public func createModuleArrayFromJSONInSubjects()
let modules = getModuleArrayFromJSON(moduleArrayJSON: (maths?.moduleArrayJSON)!)
for module in modules
print("-> " + module.title!)
maths?.setModules(modules: modules)
for module in (maths?.getModules())!
print("---> " + module.title!)
I am unable to figure this out, it seems weird.
Am i missing something?
ios realm swift4
What isModule
type - is this also a Realm object? And is themaths
object managed by Realm (i.e. stored in a Realm)?
– Chris Shaw
Mar 6 at 22:19
add a comment |
I am using a class LocalSubject.swift which i store in a RealmDB.
class LocalSubject: Object
@objc dynamic var subjectName: String?
private var modules: [Module] = [Module]()
@objc dynamic var moduleArrayJSON: String? = nil
public func addModule(module: Module)
modules.append(module)
public func setModules(modules: [Module])
self.modules = modules
print("LocalSubject.swift > setModules() > " + String(describing: modules.count) + " > " + String(describing: self.modules.count))
public func getModules()-> [Module]
print("LocalSubject.swift > getModules() > " + String(describing: modules.count) + " > " + String(describing: self.modules.count))
return modules.sorted(by: $0.displayOrder! < $1.displayOrder!)
I store the class in DB by converting "modules" array to json & back.
In below function, "modules" is computed correctly with count = 3, then i set it in "maths" object of LocalSubject. Now when i try to get the "modules" from "maths", i am always getting an empty array.
public func createModuleArrayFromJSONInSubjects()
let modules = getModuleArrayFromJSON(moduleArrayJSON: (maths?.moduleArrayJSON)!)
for module in modules
print("-> " + module.title!)
maths?.setModules(modules: modules)
for module in (maths?.getModules())!
print("---> " + module.title!)
I am unable to figure this out, it seems weird.
Am i missing something?
ios realm swift4
I am using a class LocalSubject.swift which i store in a RealmDB.
class LocalSubject: Object
@objc dynamic var subjectName: String?
private var modules: [Module] = [Module]()
@objc dynamic var moduleArrayJSON: String? = nil
public func addModule(module: Module)
modules.append(module)
public func setModules(modules: [Module])
self.modules = modules
print("LocalSubject.swift > setModules() > " + String(describing: modules.count) + " > " + String(describing: self.modules.count))
public func getModules()-> [Module]
print("LocalSubject.swift > getModules() > " + String(describing: modules.count) + " > " + String(describing: self.modules.count))
return modules.sorted(by: $0.displayOrder! < $1.displayOrder!)
I store the class in DB by converting "modules" array to json & back.
In below function, "modules" is computed correctly with count = 3, then i set it in "maths" object of LocalSubject. Now when i try to get the "modules" from "maths", i am always getting an empty array.
public func createModuleArrayFromJSONInSubjects()
let modules = getModuleArrayFromJSON(moduleArrayJSON: (maths?.moduleArrayJSON)!)
for module in modules
print("-> " + module.title!)
maths?.setModules(modules: modules)
for module in (maths?.getModules())!
print("---> " + module.title!)
I am unable to figure this out, it seems weird.
Am i missing something?
ios realm swift4
ios realm swift4
asked Mar 6 at 18:38
Manvendra SahManvendra Sah
369
369
What isModule
type - is this also a Realm object? And is themaths
object managed by Realm (i.e. stored in a Realm)?
– Chris Shaw
Mar 6 at 22:19
add a comment |
What isModule
type - is this also a Realm object? And is themaths
object managed by Realm (i.e. stored in a Realm)?
– Chris Shaw
Mar 6 at 22:19
What is
Module
type - is this also a Realm object? And is the maths
object managed by Realm (i.e. stored in a Realm)?– Chris Shaw
Mar 6 at 22:19
What is
Module
type - is this also a Realm object? And is the maths
object managed by Realm (i.e. stored in a Realm)?– Chris Shaw
Mar 6 at 22:19
add a comment |
1 Answer
1
active
oldest
votes
Realm objects do not support array types, instead you should use the Realm type List
to maintain references to other Realm objects. If Module
is not a Realm object subclass, you can't store a reference to it. See here: https://realm.io/docs/swift/latest/#models
So there are two options:
- Either change the
modules
property to be aList
and maintain theModule
objects in Realm too, or - Do you need to store the
modules
property if you are storing the JSON? You could continue to store the JSON string only, and makemodules
a computed property (for which you'd need agetter
, and you can choose whether to make asetter
or not).
You'll have to choose the way forward depending on your use cases.
Thanks for the direction. I chose option 2 and things worked out for me.
– Manvendra Sah
Mar 7 at 6:20
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55030063%2fweird-thing-hapening-while-setting-and-getting-array-in-swift4%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Realm objects do not support array types, instead you should use the Realm type List
to maintain references to other Realm objects. If Module
is not a Realm object subclass, you can't store a reference to it. See here: https://realm.io/docs/swift/latest/#models
So there are two options:
- Either change the
modules
property to be aList
and maintain theModule
objects in Realm too, or - Do you need to store the
modules
property if you are storing the JSON? You could continue to store the JSON string only, and makemodules
a computed property (for which you'd need agetter
, and you can choose whether to make asetter
or not).
You'll have to choose the way forward depending on your use cases.
Thanks for the direction. I chose option 2 and things worked out for me.
– Manvendra Sah
Mar 7 at 6:20
add a comment |
Realm objects do not support array types, instead you should use the Realm type List
to maintain references to other Realm objects. If Module
is not a Realm object subclass, you can't store a reference to it. See here: https://realm.io/docs/swift/latest/#models
So there are two options:
- Either change the
modules
property to be aList
and maintain theModule
objects in Realm too, or - Do you need to store the
modules
property if you are storing the JSON? You could continue to store the JSON string only, and makemodules
a computed property (for which you'd need agetter
, and you can choose whether to make asetter
or not).
You'll have to choose the way forward depending on your use cases.
Thanks for the direction. I chose option 2 and things worked out for me.
– Manvendra Sah
Mar 7 at 6:20
add a comment |
Realm objects do not support array types, instead you should use the Realm type List
to maintain references to other Realm objects. If Module
is not a Realm object subclass, you can't store a reference to it. See here: https://realm.io/docs/swift/latest/#models
So there are two options:
- Either change the
modules
property to be aList
and maintain theModule
objects in Realm too, or - Do you need to store the
modules
property if you are storing the JSON? You could continue to store the JSON string only, and makemodules
a computed property (for which you'd need agetter
, and you can choose whether to make asetter
or not).
You'll have to choose the way forward depending on your use cases.
Realm objects do not support array types, instead you should use the Realm type List
to maintain references to other Realm objects. If Module
is not a Realm object subclass, you can't store a reference to it. See here: https://realm.io/docs/swift/latest/#models
So there are two options:
- Either change the
modules
property to be aList
and maintain theModule
objects in Realm too, or - Do you need to store the
modules
property if you are storing the JSON? You could continue to store the JSON string only, and makemodules
a computed property (for which you'd need agetter
, and you can choose whether to make asetter
or not).
You'll have to choose the way forward depending on your use cases.
answered Mar 6 at 22:58
Chris ShawChris Shaw
33318
33318
Thanks for the direction. I chose option 2 and things worked out for me.
– Manvendra Sah
Mar 7 at 6:20
add a comment |
Thanks for the direction. I chose option 2 and things worked out for me.
– Manvendra Sah
Mar 7 at 6:20
Thanks for the direction. I chose option 2 and things worked out for me.
– Manvendra Sah
Mar 7 at 6:20
Thanks for the direction. I chose option 2 and things worked out for me.
– Manvendra Sah
Mar 7 at 6:20
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55030063%2fweird-thing-hapening-while-setting-and-getting-array-in-swift4%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What is
Module
type - is this also a Realm object? And is themaths
object managed by Realm (i.e. stored in a Realm)?– Chris Shaw
Mar 6 at 22:19