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










0















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?










share|improve this question






















  • 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















0















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?










share|improve this question






















  • 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













0












0








0








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?










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 6 at 18:38









Manvendra SahManvendra Sah

369




369












  • 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
















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












1 Answer
1






active

oldest

votes


















1














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:



  1. Either change the modules property to be a List and maintain the Module objects in Realm too, or

  2. Do you need to store the modules property if you are storing the JSON? You could continue to store the JSON string only, and make modules a computed property (for which you'd need a getter, and you can choose whether to make a setter or not).

You'll have to choose the way forward depending on your use cases.






share|improve this answer























  • Thanks for the direction. I chose option 2 and things worked out for me.

    – Manvendra Sah
    Mar 7 at 6:20










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
);



);













draft saved

draft discarded


















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









1














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:



  1. Either change the modules property to be a List and maintain the Module objects in Realm too, or

  2. Do you need to store the modules property if you are storing the JSON? You could continue to store the JSON string only, and make modules a computed property (for which you'd need a getter, and you can choose whether to make a setter or not).

You'll have to choose the way forward depending on your use cases.






share|improve this answer























  • Thanks for the direction. I chose option 2 and things worked out for me.

    – Manvendra Sah
    Mar 7 at 6:20















1














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:



  1. Either change the modules property to be a List and maintain the Module objects in Realm too, or

  2. Do you need to store the modules property if you are storing the JSON? You could continue to store the JSON string only, and make modules a computed property (for which you'd need a getter, and you can choose whether to make a setter or not).

You'll have to choose the way forward depending on your use cases.






share|improve this answer























  • Thanks for the direction. I chose option 2 and things worked out for me.

    – Manvendra Sah
    Mar 7 at 6:20













1












1








1







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:



  1. Either change the modules property to be a List and maintain the Module objects in Realm too, or

  2. Do you need to store the modules property if you are storing the JSON? You could continue to store the JSON string only, and make modules a computed property (for which you'd need a getter, and you can choose whether to make a setter or not).

You'll have to choose the way forward depending on your use cases.






share|improve this answer













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:



  1. Either change the modules property to be a List and maintain the Module objects in Realm too, or

  2. Do you need to store the modules property if you are storing the JSON? You could continue to store the JSON string only, and make modules a computed property (for which you'd need a getter, and you can choose whether to make a setter or not).

You'll have to choose the way forward depending on your use cases.







share|improve this answer












share|improve this answer



share|improve this answer










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

















  • 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



















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved