Re: [swift-users] porting to musl (was: building static binaries / reducing library dependencies?)

2015-12-28 Thread Drew Crawford via swift-users

> On Dec 28, 2015, at 7:20 PM, Joe Groff  wrote:
> 
> I can believe LLVM and Clang only build against glibc, but that's not 
> necessarily a problem for compiled executables.

I was attempting to build Swift on a system (specifically, Alpine) which does 
not have a glibc package.

It may very well be possible to design a cross-compile toolchain to build 
glibc-free Swift executables from a glibc system.  That kind of question is 
well outside my knowledge.

But that particular rabbithole does not lead to a swift package for Alpine, so 
unfortunately, it is of small help for my motivation.___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


[swift-users] Lazily populated dictionary

2015-12-28 Thread Rudolf Adamkovič via swift-users
Hi there!

In my app, I have a very simple class that serves as a key-value cache. The 
whole thing is basically a lazily populated [String: AVAudioPCMBuffer] 
dictionary with a String -> AVAudioPCMBuffer function that generates values as 
needed:

final class PlayerAudioCache {

// MARK: Retrieving audio buffers

func audioBufferForAssetWithName(name: String) -> AVAudioPCMBuffer? {
addAudioBufferForAssetWithNameIfNeeded(name)
return cachedAudioBuffers[name]
}

// MARK: Adding audio buffers

func addAudioBufferForAssetWithNameIfNeeded(name: String) {
guard cachedAudioBuffers[name] == nil else { return }
addAudioBufferForAssetWithName(name)
}

private func addAudioBufferForAssetWithName(name: String) {
guard let dataAsset = NSDataAsset(name: name) else { fatalError() }
cachedAudioBuffers[name] = dataAsset.map { URL -> AVAudioPCMBuffer in
AVAudioPCMBuffer(contentsOfURL: URL)!
}
}

private var cachedAudioBuffers: [String: AVAudioPCMBuffer] = [:]

}

I feel like there is a pre-made type in Swift’s standard library for what I’m 
doing here. Am I right?

Ideas? Pointers?

Thank you!

R+___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


[swift-users] Going a little crazy with the Swift Package Manager

2015-12-28 Thread Erica Sadun via swift-users
If anyone could kick the wheels and/or give feedback:

SwiftString  (should be okay on apple and 
linux)
SwiftUtility  (should be okay for apple 
and linux)
SwiftFoundationAdditions  
(best for non-linux, although I'm curious how they'll run on linux)

Please do let me know if you think there's anything there worth pushing forward 
to the language.

Thanks, -- Erica

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Lazily populated dictionary

2015-12-28 Thread Erica Sadun via swift-users
Maybe something like this?

struct KeyedLazyCache {
var backingDictionary: Dictionary
var builderDictionary: Dictionary U>
mutating func clear() {backingDictionary.removeAll()}
mutating func valueForKey(key: T) -> U? {
if let value = backingDictionary[key] {return value}
if let builder = builderDictionary[key] {
let value = builder()
backingDictionary[key] = value
return value
}
return nil
}
}

-- E

> On Dec 28, 2015, at 11:36 AM, Rudolf Adamkovič via swift-users 
>  wrote:
> 
> Hi there!
> 
> In my app, I have a very simple class that serves as a key-value cache. The 
> whole thing is basically a lazily populated [String: AVAudioPCMBuffer] 
> dictionary with a String -> AVAudioPCMBuffer function that generates values 
> as needed:
> 
> final class PlayerAudioCache {
> 
> // MARK: Retrieving audio buffers
> 
> func audioBufferForAssetWithName(name: String) -> AVAudioPCMBuffer? {
> addAudioBufferForAssetWithNameIfNeeded(name)
> return cachedAudioBuffers[name]
> }
> 
> // MARK: Adding audio buffers
> 
> func addAudioBufferForAssetWithNameIfNeeded(name: String) {
> guard cachedAudioBuffers[name] == nil else { return }
> addAudioBufferForAssetWithName(name)
> }
> 
> private func addAudioBufferForAssetWithName(name: String) {
> guard let dataAsset = NSDataAsset(name: name) else { fatalError() }
> cachedAudioBuffers[name] = dataAsset.map { URL -> AVAudioPCMBuffer in
> AVAudioPCMBuffer(contentsOfURL: URL)!
> }
> }
> 
> private var cachedAudioBuffers: [String: AVAudioPCMBuffer] = [:]
> 
> }
> 
> I feel like there is a pre-made type in Swift’s standard library for what I’m 
> doing here. Am I right?
> 
> Ideas? Pointers?
> 
> Thank you!
> 
> R+
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Recursive Enums and String Literals

2015-12-28 Thread Joe Groff via swift-users

> On Dec 27, 2015, at 2:14 AM, Rick Gigger via swift-users 
>  wrote:
> 
> I am trying to create an enum that will allow me to create literals that 
> combine Int, Double and String types, as well as any Array of any combination 
> of those, and any Dictionary mapping a String to any combination of those. 
> And make it nestable.
> 
> First I have the enum itself, and then several examples. Everything complies 
> cleanly except for dict4 and dict5.
> 
> Is type inference not expected to work for recursive enums? Or is this a bug 
> in the compiler? If not is there any way to do this in pure swift that will 
> compile?
> 
> I realize that it's sort of unswifty to have such unstructured, stringly 
> typed data like this. But in a pinch sometimes it's useful.
> 
> Copy and paste this into a Playground to see the error message. (Contextual 
> type 'protocol <>' cannot be used with array literal and Contextual type 
> 'protocol <>' cannot be used with dictionary literal)

`Any` is a typealias for the `protocol<>` type, so the type checker's 
complaining that it's unable to find a suitable 
Array/DictionaryLiteralConvertible type. This is arguably a bug, since the type 
checker's supposed to fall back to Array/Dictionary as defaults in 
unconstrained cases like this, but I think it's helping you out here, since you 
really want to build your data structure out of RecursiveAny rather than 
unconstrained Any values. If you replace `Any` with `RecursiveAny` in your 
anyDict/anyArr payload types, it should work.

-Joe

> enum RecursiveAny: StringLiteralConvertible, ArrayLiteralConvertible, 
> IntegerLiteralConvertible, BooleanLiteralConvertible, 
> FloatLiteralConvertible, DictionaryLiteralConvertible {
> case any(Any)
> indirect case anyDict([String:Any])
> indirect case anyArr([Any])
> 
> // string literal convertible
> init(stringLiteral value: String) {
> self = .any(value)
> }
> 
> init(extendedGraphemeClusterLiteral value: String) {
> self = .any(value)
> }
> 
> init(unicodeScalarLiteral value: String) {
> self = .any(value)
> }
> 
> // array literal convertible
> init(arrayLiteral elements: Any...) {
> self = .anyArr(elements)
> }
> 
> init(dictionaryLiteral elements: (String, Any)...) {
> var dict = [String:Any]()
> for (key, value) in elements {
> dict[key] = value
> }
> self = .anyDict(dict)
> }
> 
> // integer literal convertible
> init(integerLiteral value: Int) {
> self = .any(value)
> }
> 
> // boolean literal convertible
> init(booleanLiteral value: Bool) {
> self = .any(value)
> }
> 
> // float literal convertible
> init(floatLiteral value: Double) {
> self = .any(value)
> }
> }
> 
> let string: RecursiveAny = "asdf"
> let int: RecursiveAny = 3
> let float: RecursiveAny = 5.6
> let array: RecursiveAny = ["asdf", 3, 5.6]
> let dict: RecursiveAny = [
> "string": "asdf",
> "int": 3,
> "float": 5.6
> ]
> let dict2: RecursiveAny = [
> "string": "asdf",
> "int": 3,
> "float": 5.6,
> "array": array
> ]
> let dict3: RecursiveAny = [
> "string": "asdf",
> "int": 3,
> "float": 5.6,
> "array": dict
> ]
> let dict4: RecursiveAny = [
> "string": "asdf",
> "int": 3,
> "float": 5.6,
> "array": ["asdf", 3, 5.6]
> ]
> let dict5: RecursiveAny = [
> "string": "asdf",
> "int": 3,
> "float": 5.6,
> "dict": [
> "string": "asdf",
> "int": 3,
> "float": 5.6
> ]
> ]
> 
> let dict6: RecursiveAny = [
> "string": "asdf",
> "int": 3,
> "float": 5.6,
> "array": RecursiveAny.anyArr(["asdf", 3, 5.6])
> ]
> let dict7: RecursiveAny = [
> "string": "asdf",
> "int": 3,
> "float": 5.6,
> "dict": RecursiveAny.anyDict([
> "string": "asdf",
> "int": 3,
> "float": 5.6
> ])
> ]
> 
>  ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


[swift-users] Mac Toolchain is Unsigned?

2015-12-28 Thread John Lin via swift-users
> On 25/12/15 15:00 , swift-users-request at swift.org 
>  wrote:
> > Date: Fri, 25 Dec 2015 09:43:31 -0800
> > From: Dmitri Gribenko  > >
> > To: swizzlr  > > Cc:
> > Message-ID:  > mail.gmail.com >
> >> >
> >>> While I wait for the rest of the family to arrive and the kids
> >>> are slowly going insane staring at presents, I’m doing some Swift
> >>> dev. However, I note that the latest Mac snapshot is unsigned –
> >>> has it always been this way? The installer displays the lock, but
> >>> I have to option-click on the package to actually get it
> >>> running.
> 
> > I just checked, it is signed.  Here’s the SHA-1 hash on my end:
> > 
> > 68e2ba878d2c9803bbfda760b24b399e8ada4f79
> > swift-2.2-SNAPSHOT-2015-12-22-a-osx.pkg
> 
> FWIW, version 1.1.5 and up of my RB App Checker Lite
> (http://brockerhoff.net/RB/AppCheckerLite 
> ) now can show signatures for
> this type of package, too.
> 
> Enjoy,
> 
I got some issue on verifying the code signing too.
I got Xcode 7.2 installed on Yosemite , updated to El Capitan , install 
toolchain.
I got "a sealed resource is missing or invalid” error when launching Xcode with 
the toolchain.
I tried to install toolchain again, not working.
Tried to install toolchain with debug symbol, not working.
Remove Xcode and install Xcode again, not working.
I verified the toolchain with 
odesign --verify - -R='anchor apple generic and certificate 
1[field.1.2.840.113635.100.6.2.1] exists and (certificate 
leaf[field.1.2.840.113635.100.6.1.2] exists or certificate 
leaf[field.1.2.840.113635.100.6.1.4] exists)' 
swift-2.2-SNAPSHOT-2015-12-22-a.xctoolchain
it shows the same "a sealed resource is missing or invalid”
At last I sudo remove the whole Library/Developer/Toolchains dir, then 
reinstall the toolchain, it finally start working.

Best, 
John___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users