• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Converting to Swift
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Converting to Swift


  • Subject: Re: Converting to Swift
  • From: "Gerriet M. Denkmann" <email@hidden>
  • Date: Mon, 11 Aug 2014 16:54:28 +0700

On 11 Aug 2014, at 16:05, Bavarious <email@hidden> wrote:

>
>> On 11 Aug 2014, at 05:53, Gerriet M. Denkmann <email@hidden> wrote:
>>
>>
>> On 11 Aug 2014, at 15:43, Bavarious <email@hidden> wrote:
>>
>>> On 11 Aug 2014, at 05:35, Gerriet M. Denkmann <email@hidden> wrote:
>>>>
>>>> I am trying to convert:
>>>> 	NSString * helperName = @"de.mdenkmann.Xpc-Exchange”;
>>>> 	CFDictionaryRef diref = SMJobCopyDictionary( kSMDomainSystemLaunchd, (__bridge CFStringRef)helperName );
>>>> 	NSDictionary *jobDict = (NSDictionary *)CFBridgingRelease(diref);
>>>> 	if ( jobDict == nil ) need to start the helper
>>>>
>>>> to Swift:
>>>> 	let name = xpcServiceName!
>>>> 	let diref = SMJobCopyDictionary( kSMDomainSystemLaunchd, name )
>>>> but get an error for name: "'NSString' is not a subtype of 'CFString'"
>>>>
>>>> 	let cref = CFString(name) → error:  'CFString' cannot be constructed because it has no accessible initializers
>>>>
>>>> How to get a CFString?
>>>
>>>
>>>
>>> let cfname = name as CFString
>>>
>>> should work.
>>
>> You are right: it should work.
>> But
>> 	let cref = name as CFString
>> again created the error: 'NSString' is not a subtype of 'CFString'
>>
>> Xcode 6 beta 5
>
> What is the type of xpcServiceName? If it’s a Swift string, you need to go through NSString first. If it’s an NSString, just as CFString should work.
>
> I get no compiler errors with this code:
>
> import Foundation
>
> let s = "string"
> let nss = s as NSString
> let cfs1 = s as NSString as CFString
> let cfs2 = nss as CFString

let name1 = xpcServiceName!
let name2 = name1 as NSString
let name3 = name2 as CFString
let diref = SMJobCopyDictionary( kSMDomainSystemLaunchd, name3 )
let jobDictionary = diref.takeRetainedValue()	<--- I hope this is right
if jobDictionary == nil
{
	println("Helper not running")
}
else
{
	println("Helper JobCopyDictionary = \(jobDictionary)")
}

This works perfectly.
Thank you very much!

Kind regards,

Gerriet.


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


References: 
 >Converting to Swift (From: "Gerriet M. Denkmann" <email@hidden>)
 >Re: Converting to Swift (From: Bavarious <email@hidden>)
 >Re: Converting to Swift (From: "Gerriet M. Denkmann" <email@hidden>)
 >Re: Converting to Swift (From: Bavarious <email@hidden>)

  • Prev by Date: how can i change the UITabBarItem title's color
  • Next by Date: How to make a LaunchAgent
  • Previous by thread: Re: Converting to Swift
  • Next by thread: how can i change the UITabBarItem title's color
  • Index(es):
    • Date
    • Thread