Realm, Configuration and app groups - swift

I'd like to use Realm with app groups to be able to share data with watch extension. I'm facing problem, that when I try to configure default realm.. By that I mean that I create new path and then I create new configuration. So far so good, but when I try to set this configuration as defaultConfiguration, nothing happens. For better idea check screenshot where is my code plus console output. Any idea? Thank you

The defaultConfiguration you set on Realm.Configuration is used to initialize new Realms. So if you would print the path of a Realm instance, e.g. try! Realm().path, then this would reflect the path from the shared app group. You did instead initialize a new & fresh configuration, which always uses the initial default values.

Related

Core Data Entities multiple build configurations

I have 3 build configurations, Debug, Release and Development. For Development I have created a new Scheme with a new bundleID, Product name etc so I can see which one is DEV and DEBUG on my phone.
I am using Core Data and for the DEBUG with the original bundleID everything works fine, but when I switch to use the Development one, I get an error when I try to create a new entity with name:
NSEntityDescription.insertNewObject(forEntityName: "MyEntity", into: managedContext)
The error I get:
Could not cast value of type 'NSManagedObject_MyEntity_' (0x600002d62b20) to 'AppName_DEV.MyEntity' (0x102bf9368).
It seems like it is trying to get the MyEntity class from my "AppName DEV" scheme not the "AppName". I can't find any Build Settings where I could point it to use the same model?
Any ideas on how to use core data with multiple build configurations?
Ok, I found the problem. Since I was trying to revive a very old app originally written in swift 2, it occurred to me that I might double check how was the data model created. After hours of tinkering with the core data set up process, I changed 2 things that finally get it to work.
1.) In the .xcdatamodeld file, on the right side in the Data Model Inspector, make sure that you have the Module field EMPTY I had my AppName Inside, which was the same as the original target name.
2.) I added #objc(EntityName) to the NSManagedObject subclass I had.
Of course I cleaned the project, deleted the app from the simulator and installed it again.
If you have an issue like that, hope that whis will help you, good luck!

Clone rep:policy on AEM

I am currently working on with a solution that would be able to clone/copy/backup my existing rep:policy. 'Cause when we do some jobs it accidentally removed. I am trying to apply this kind of fix, but am failing to. It says it is an invalid path.
javax.jcr.security.AccessControlException: OakAccessControl0006: Isolated policy node. Parent is not of type [rep:AccessControllable]
final Workspace ws = session.getWorkspace();
ws.copy("/etc/commerce/products/abccompany/TvPackChannelMap/rep:policy","/tmp/nxt/TvPackChannelMap/rep:policy");
Are there other ways that I can be able to take the rep:policy thru code?
You need to make sure that your job does not touch the permissions or the rep:policy, this is the best way forward for you.
The exception could be because of /etc/commerce/products/abccompany/TvPackChannelMap/rep:policy does not exist or the user whose session you are using does not have read access to the node.
Make sure the path is correct, copy paste it to your CRX/DE to make sure it exists.
I have tried to use your code to copy a rep:policy from one node to another, works fine. But I would not* recommend copying permissions that way. The best practice is to use the Access Control Management API for all things permissions.
You can check, install and use the access control tool from netcentric. It offers a jmx interface for exporting AC entries and maybe also some APIs you could use to implement your custom solution.
The Other approach is to retrieve the ACL permissions through the query language.
For example, SELECT * FROM [rep:ACL] or SELECT * FROM [rep:ACE] where [rep:principalName] is not null should give you the results.
For more information, I would recommend you to check the ACS commons ACL Packager Implementation which is available on GitHub.
Reference Link - https://github.com/Adobe-Consulting-Services/acs-aem-commons/blob/master/bundle/src/main/java/com/adobe/acs/commons/packaging/impl/ACLPackagerServletImpl.java

In CQ5, my responsive emulator devices list is empty

To start, I followed these directions exactly as it's stated: http://dev.day.com/docs/en/cq/5-6/developing/mobile/responsive.html
The problem is, despite all of that, my Devices dropdown on the sidekick in preview mode is empty.
The list works without issue in the Geometrixx Media without issue.
I made sure I set the cq:deviceGroups and the sling:OsgiConfig as required, and also included the simulator.js in the head tags.
Edit: I have found that if I set the resourceType on the root level page to geometrixx-media/components/page, which is their working demo, it works. I have completely removed all jsp and config items from that component page and it still continues to work anyways.
Does anyone know of something that is missing from the documents, and how to fix the issue?
Thanks.
This is what I did to resolve this issue:
I am going to assume your application name is jason-riis
In CRXDE|Lite create a config folder in /apps/jason-riis/
Now create a node of:
TYPE=sling:OsgiConfig
NAME=com.day.cq.wcm.mobile.core.impl.MobileEmulatorProvider-<*alias>
*alias could be anything, I gave my application name. What it does is it will get you a unique PID when you look at it in configuration Manager
If you go to your configuration manager now, you should be able to see two MobileEmulatorProvider config settings.
Add a node property to node you just created:
NAME=mobile.resourceTypes
TYPE=String[] (you have to click multi at the end of the value textbox)
VALUE=jason-riis/components/<*page>
*page is all the components that has sling:resourceSuperType of foundation/components/page and it is a multi array so it should look like this
jason-riis/components/page, jason-riis/components/widepage, jason-riis/components/newspage
I assume you already have the cq:include for simulation in your header. This makes the devices button appear in preview mode.
Last thing is, go to your website root page's jcr:content [/content/jason-riis/jcr:content] and add node property
NAME=cq:deviceGroups
TYPE=String[]
*VALUE=/etc/mobile/groups/touch, /etc/mobile/groups/smart
*If you go to this etc path in CRXDE|Lite; you will see more relevant information in jcr:content node. This will help you in creating your own custom emulator list.
You should be able to see the dropdown now, with options of iPhone and iPad and all. I know AEM docs are frustrating, let me know if there is any confusion.

setting options while installing or after installing App

I want to set the language for one time once the user downloaded the app and started using it, for only first time. but not all the time he use the app. How can i do that?
like how we get select language options , while installing Microsoft products, etc
is this possible ?
you can control that when you application apears. Did you know about property lists?
You could use it. Or maybe you can create a file with Core data with name Configs. You need to check if field is blank and case yes, open a viewControllerChangeLanguange.After select save the data and start your application. Remember, everytime you start you will check your file. Case exists, set current language.Case not, invoke an interface to user select a language. All the controller could be made by just a file config.

How to Specify for XCode to Execute Specific Lines of Code or Not Depending Upon Profile

I tried to get my head around schemes, configurations, entitlements and what not and all Iam right now is a mighty confused fellow.
We have 3 people working on an iOS application. I am working on connecting the application to a remote server which is giving out a lot of errors and so when I actually commit the progress, everyone's copy of the application gets the problem. I want to make a kind of profile that I can use so that the other folks can skip the lines of code when they run XCode with their profile.
Is there any way this can be done?
EDIT: I think I am looking for Preprocessor Macros to define a condition. I want to do a
#if Value = Local
//get data locally
#if Value = Remote
//get data from server
How do I so this? Also, how do I assign this "value" a value.
You're trying to solve the wrong problem. If you've got a work-in-progress, you shouldn't be trying to conditionally execute certain lines of code depending on who builds it, you should contain your work-in-progress to a feature branch. This is not an issue that should be solved during execution, this is a collaboration issue that should be solved with source control.
As per your edit, you can convert this idea to
#if Value = Local
//get data locally
#if Value = Remote
//get data from server
Implement above as:
#ifdef LOCAL_DB
//get data locally
#else
//get data from server
#endif