-1

In the new contacts framework, I am trying to add social profiles and I am using a line of code that works in other projects, but for some reason it just does not work in the particular one that I am working in. Here is the code below

let twitterProfile = CNLabeledValue(label: "Twitter", value:
CNSocialProfile(urlString: nil, username: "ios_blog",
userIdentifier: nil, service: CNSocialProfileServiceTwitter))

contactData.socialProfiles = [twitterProfile]

I keep getting this error message: "Cannot Subscript a value of type CNLabeledValue<CNSocialProfile> with an index of type CNLabeledValue<CNSocialProfile>."

If I put it in another project it works, but I would need it to work in mine and for some reason I just keep getting this error.

I would really appreciate if someone could tell me what I am doing wrong.

Dave Weston
  • 6,527
  • 1
  • 29
  • 44
  • Which line exactly is giving you the issue? It doesn't look like you're trying to subscript anything in this code. Can you include the definition of `contactData`? – Dave Weston Jan 23 '17 at 00:43
  • let contactData = CNMutableContact() – user7208112 Jan 23 '17 at 00:48
  • let contactData = CNMutableContact() I'm not doing anything wrong in terms of that, and If I try to save the phoneNumber, name etd. That is working, I am only having the issue with the socialProfiles. I think some other parts of the code might cause this, but I have no idea what. Thank you!- @Dave Weston – user7208112 Jan 23 '17 at 00:54
  • As I understand it, that error is coming from the compiler, correct? Which line exactly is it complaining about? Can you try commenting out the line where you assign to the `socialProfiles` property and see if the error message goes away or changes at all? – Dave Weston Jan 23 '17 at 01:08
  • It is not the compiler, I am unable to even run the code, it recognizes the error before I run it. I have no idea which part of the code should I share since this I never saw an error like this before. Thank You guys, let me know what you think. @Dave Weston – user7208112 Jan 23 '17 at 02:00

2 Answers2

1

Your problem cannot be reproduced as described. This code compiles and runs just fine:

let contactData = CNMutableContact()
let twitterProfile = CNLabeledValue(label: "Twitter", value: CNSocialProfile(urlString: nil, username: "ios_blog", userIdentifier: nil, service: CNSocialProfileServiceTwitter))
contactData.socialProfiles = [twitterProfile]

It is all very well to say that this problem is caused by other code, and that may be true, but you didn't show us any other code. The code you did show us, works.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • Actually I suspect that the line the compiler is complaining about is some other line entirely. I can't see anything about the code you supplied that would elicit any mention of indexing. – matt Jan 23 '17 at 01:12
  • It is not the compiler, I am unable to even run the code, it recognizes the error before I run it. I have no idea which part of the code should I share since this I never saw an error like this before. Thank You guys, let me know what you think. @matt – user7208112 Jan 23 '17 at 01:58
  • I actually solved that issue, and I do not use getters anymore, however I ran into another issue, this issue happens when I try adding the social profiles and I get this SIGABRT error – user7208112 Jan 23 '17 at 05:13
  • 2017-01-23 00:10:11.323693 FVSCANNER[765:154249] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles 2017-01-23 00:10:11.325124 FVSCANNER[765:154249] [MC] Reading from public effective user settings. Could not cast value of type 'FVSCANNER.starter' (0x1001f4d80) to 'UINavigationController' (0x1a8cf8748). 2017-01-23 00:10:15.276951 FVSCANNER[765:154249] Could not cast value of type 'FVSCANNER.starter' (0x1001f4d80) to 'UINavigationController' (0x1a8cf8748). (lldb) – user7208112 Jan 23 '17 at 05:16
  • You should add an answer describing the reason for the original issue and what you did to fix it. Then you should create a new question for the SIGABRT error. – Dave Weston Jan 23 '17 at 19:09
  • Hey, I did what you asked, could you please refer to this link? https://stackoverflow.com/questions/41799682/contacts-framework-social-profiles-sigabrt-error-in-swift @DaveWeston – user7208112 Jan 23 '17 at 19:51
0

The solution is, that in the method I was getting an error was a getter and that is why it didn't work. In order to fix it, you need to use a function.