Re: [swift-users] appending packed bytes to [UInt8]

2018-01-10 Thread Kelvin Ma via swift-users
I thought tuples, like structs do *not* have fixed layout. And they get
padded too.

On Wed, Jan 10, 2018 at 5:01 PM, Nevin Brackett-Rozinsky <
nevin.brackettrozin...@gmail.com> wrote:

> Conversely, since I’m pretty sure the memory layout of a *tuple* is
> guaranteed to be as it appears, I would probably start with something like
> this:
>
> typealias Vec3rgba = (x: Float, y: Float, z: Float, r: Int8, g: Int8, b:
> Int8, a: Int8)
>
> Nevin
>
>
> On Wed, Jan 10, 2018 at 4:27 PM, Jens Persson via swift-users <
> swift-users@swift.org> wrote:
>
>> I'm not sure what you mean by "I need the buffer to be a vector /.../"
>> but perhaps this may be of some help:
>>
>> struct S {
>> var x: Float
>> var y: Float
>> var z: Float
>> var r: UInt8
>> var g: UInt8
>> var b: UInt8
>> var a: UInt8
>> }
>> var buf = S(x: 0.1, y: 1.2, z: 2.3, r: 11, g: 22, b: 33, a: 44)
>> print(MemoryLayout.stride) // 16
>> withUnsafeMutableBytes(of: ) { ptr in
>> print("x:", ptr.load(fromByteOffset: 0, as: Float.self)) // 0.1
>> print("y:", ptr.load(fromByteOffset: 4, as: Float.self)) // 1.2
>> print("z:", ptr.load(fromByteOffset: 8, as: Float.self)) // 2.3
>> print("r:", ptr.load(fromByteOffset: 12, as: UInt8.self)) // 11
>> print("g:", ptr.load(fromByteOffset: 13, as: UInt8.self)) // 22
>> print("b:", ptr.load(fromByteOffset: 14, as: UInt8.self)) // 33
>> print("a:", ptr.load(fromByteOffset: 15, as: UInt8.self)) // 44
>> }
>>
>> NOTE however that the memory layout of Swift-structs is not guaranteed to
>> remain like this and is thus not future-proof, although I think that
>> if/when things changes, there will be some way to tell the compiler that
>> you want the memory to be this "expected" "C-like" layout.
>>
>> /Jens
>>
>>
>> On Wed, Jan 10, 2018 at 10:03 PM, Kelvin Ma via swift-users <
>> swift-users@swift.org> wrote:
>>
>>> I want to create a buffer with the layout
>>>
>>> 0   4   8   12  13  14  15  16
>>> [   x:Float   |   y:Float   |   z:Float   | r:UInt8 | g:UInt8 | b:UInt8
>>> | _:UInt8 ]
>>>
>>> Normally, I’d use UnsafeRawBufferPointer for this, but I need the
>>> buffer to be a vector (i.e. with append(_:)), and for it to return a
>>> Swift-managed Array. How should I do this? The project does not
>>> use Foundation.
>>>
>>> ___
>>> 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 mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] appending packed bytes to [UInt8]

2018-01-10 Thread Kelvin Ma via swift-users
I’ve asked similar questions in the past and everyone said this is not
valid Swift, not the least because the compiler can pad structs and
rearrange its layout. For example if there were only 3 UInt8s, the stride
should be 15, not 16 as they need to be packed densely. since they are
misaligned you also can’t use load and store (they will trap)


On Wed, Jan 10, 2018 at 4:27 PM, Jens Persson  wrote:

> I'm not sure what you mean by "I need the buffer to be a vector /.../" but
> perhaps this may be of some help:
>
> struct S {
> var x: Float
> var y: Float
> var z: Float
> var r: UInt8
> var g: UInt8
> var b: UInt8
> var a: UInt8
> }
> var buf = S(x: 0.1, y: 1.2, z: 2.3, r: 11, g: 22, b: 33, a: 44)
> print(MemoryLayout.stride) // 16
> withUnsafeMutableBytes(of: ) { ptr in
> print("x:", ptr.load(fromByteOffset: 0, as: Float.self)) // 0.1
> print("y:", ptr.load(fromByteOffset: 4, as: Float.self)) // 1.2
> print("z:", ptr.load(fromByteOffset: 8, as: Float.self)) // 2.3
> print("r:", ptr.load(fromByteOffset: 12, as: UInt8.self)) // 11
> print("g:", ptr.load(fromByteOffset: 13, as: UInt8.self)) // 22
> print("b:", ptr.load(fromByteOffset: 14, as: UInt8.self)) // 33
> print("a:", ptr.load(fromByteOffset: 15, as: UInt8.self)) // 44
> }
>
> NOTE however that the memory layout of Swift-structs is not guaranteed to
> remain like this and is thus not future-proof, although I think that
> if/when things changes, there will be some way to tell the compiler that
> you want the memory to be this "expected" "C-like" layout.
>
> /Jens
>
>
> On Wed, Jan 10, 2018 at 10:03 PM, Kelvin Ma via swift-users <
> swift-users@swift.org> wrote:
>
>> I want to create a buffer with the layout
>>
>> 0   4   8   12  13  14  15  16
>> [   x:Float   |   y:Float   |   z:Float   | r:UInt8 | g:UInt8 | b:UInt8
>> | _:UInt8 ]
>>
>> Normally, I’d use UnsafeRawBufferPointer for this, but I need the buffer
>> to be a vector (i.e. with append(_:)), and for it to return a
>> Swift-managed Array. How should I do this? The project does not
>> use Foundation.
>>
>> ___
>> 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] appending packed bytes to [UInt8]

2018-01-10 Thread Nevin Brackett-Rozinsky via swift-users
Conversely, since I’m pretty sure the memory layout of a *tuple* is
guaranteed to be as it appears, I would probably start with something like
this:

typealias Vec3rgba = (x: Float, y: Float, z: Float, r: Int8, g: Int8, b:
Int8, a: Int8)

Nevin


On Wed, Jan 10, 2018 at 4:27 PM, Jens Persson via swift-users <
swift-users@swift.org> wrote:

> I'm not sure what you mean by "I need the buffer to be a vector /.../" but
> perhaps this may be of some help:
>
> struct S {
> var x: Float
> var y: Float
> var z: Float
> var r: UInt8
> var g: UInt8
> var b: UInt8
> var a: UInt8
> }
> var buf = S(x: 0.1, y: 1.2, z: 2.3, r: 11, g: 22, b: 33, a: 44)
> print(MemoryLayout.stride) // 16
> withUnsafeMutableBytes(of: ) { ptr in
> print("x:", ptr.load(fromByteOffset: 0, as: Float.self)) // 0.1
> print("y:", ptr.load(fromByteOffset: 4, as: Float.self)) // 1.2
> print("z:", ptr.load(fromByteOffset: 8, as: Float.self)) // 2.3
> print("r:", ptr.load(fromByteOffset: 12, as: UInt8.self)) // 11
> print("g:", ptr.load(fromByteOffset: 13, as: UInt8.self)) // 22
> print("b:", ptr.load(fromByteOffset: 14, as: UInt8.self)) // 33
> print("a:", ptr.load(fromByteOffset: 15, as: UInt8.self)) // 44
> }
>
> NOTE however that the memory layout of Swift-structs is not guaranteed to
> remain like this and is thus not future-proof, although I think that
> if/when things changes, there will be some way to tell the compiler that
> you want the memory to be this "expected" "C-like" layout.
>
> /Jens
>
>
> On Wed, Jan 10, 2018 at 10:03 PM, Kelvin Ma via swift-users <
> swift-users@swift.org> wrote:
>
>> I want to create a buffer with the layout
>>
>> 0   4   8   12  13  14  15  16
>> [   x:Float   |   y:Float   |   z:Float   | r:UInt8 | g:UInt8 | b:UInt8
>> | _:UInt8 ]
>>
>> Normally, I’d use UnsafeRawBufferPointer for this, but I need the buffer
>> to be a vector (i.e. with append(_:)), and for it to return a
>> Swift-managed Array. How should I do this? The project does not
>> use Foundation.
>>
>> ___
>> 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 mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] defaultCalendarForNewEvents is defined as optional however can't use optional binding to check if it's nil

2018-01-10 Thread Filiz Topatan via swift-users
You were right! I was using Swift 3.2 and not Swift 4.0.

Thank you!

Filiz

On Wed, Jan 10, 2018 at 10:25 AM, Jordan Rose via swift-users <
swift-users@swift.org> wrote:

> Nothing specific. A lot of minor issues were corrected in the Xcode 9
> release with a nod towards maintaining source compatibility, and most of
> them weren't release-noted.
>
> Jordan
>
>
> On Jan 10, 2018, at 10:21, Filiz Kurban  wrote:
>
> Thanks for your response. I will check that now! In the meantime, is there
> a release note that states this? I have a stackover flow question on this
> and would love to resolve it.
>
> On Wed, Jan 10, 2018 at 10:13 AM, Jordan Rose via swift-users <
> swift-users@swift.org> wrote:
>
>> Hi, Filiz. Are you sure you're using Swift 4 and not the Swift 3
>> compatibility mode? 'defaultCalendarForNewEvents' was marked non-optional
>> in Swift 3 by accident and that was fixed in Swift 4.
>>
>> Jordan
>>
>>
>> On Jan 10, 2018, at 08:59, Filiz Kurban via swift-users <
>> swift-users@swift.org> wrote:
>>
>> Hello,
>>
>> I'm adding a new functionality in my app, which is the ability to add an
>> event in the default calendar set up on the phone. In the implementation, I
>> get the permission and am ready to add the event. I check to see if there
>> is an actual default calendar through the use of optional binding, but I
>> get the error:
>>
>> Initializer for conditional binding must have Optional type, not
>> 'EKCalendar'
>>
>> Now, defaultCalendarForNewEvents is an Optional (see declaration below)
>> and it should be perfectly fine to use optional binding to check if it's
>> nil or not. What am I missing?
>>
>> defaultCalendarForNewEvents definition in EKEventStore.h:
>>
>> open var defaultCalendarForNewEvents: EKCalendar? { get }
>>
>>
>> I'm using Swift 4 on iOS11.2
>>
>> if let defaultCalendar = eventStore.defaultCalendarForNewEvents { <-- error 
>> line
>> newEvent.title = "Some Event Name"
>> newEvent.startDate = Date()
>> newEvent.endDate = Date()}
>>
>>
>> Thank you for your help in advance.
>>
>>
>> ___
>> 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 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] appending packed bytes to [UInt8]

2018-01-10 Thread Jens Persson via swift-users
I'm not sure what you mean by "I need the buffer to be a vector /.../" but
perhaps this may be of some help:

struct S {
var x: Float
var y: Float
var z: Float
var r: UInt8
var g: UInt8
var b: UInt8
var a: UInt8
}
var buf = S(x: 0.1, y: 1.2, z: 2.3, r: 11, g: 22, b: 33, a: 44)
print(MemoryLayout.stride) // 16
withUnsafeMutableBytes(of: ) { ptr in
print("x:", ptr.load(fromByteOffset: 0, as: Float.self)) // 0.1
print("y:", ptr.load(fromByteOffset: 4, as: Float.self)) // 1.2
print("z:", ptr.load(fromByteOffset: 8, as: Float.self)) // 2.3
print("r:", ptr.load(fromByteOffset: 12, as: UInt8.self)) // 11
print("g:", ptr.load(fromByteOffset: 13, as: UInt8.self)) // 22
print("b:", ptr.load(fromByteOffset: 14, as: UInt8.self)) // 33
print("a:", ptr.load(fromByteOffset: 15, as: UInt8.self)) // 44
}

NOTE however that the memory layout of Swift-structs is not guaranteed to
remain like this and is thus not future-proof, although I think that
if/when things changes, there will be some way to tell the compiler that
you want the memory to be this "expected" "C-like" layout.

/Jens


On Wed, Jan 10, 2018 at 10:03 PM, Kelvin Ma via swift-users <
swift-users@swift.org> wrote:

> I want to create a buffer with the layout
>
> 0   4   8   12  13  14  15  16
> [   x:Float   |   y:Float   |   z:Float   | r:UInt8 | g:UInt8 | b:UInt8 |
> _:UInt8 ]
>
> Normally, I’d use UnsafeRawBufferPointer for this, but I need the buffer
> to be a vector (i.e. with append(_:)), and for it to return a
> Swift-managed Array. How should I do this? The project does not
> use Foundation.
>
> ___
> 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] appending packed bytes to [UInt8]

2018-01-10 Thread Kelvin Ma via swift-users
I want to create a buffer with the layout

0   4   8   12  13  14  15  16
[   x:Float   |   y:Float   |   z:Float   | r:UInt8 | g:UInt8 | b:UInt8 |
_:UInt8 ]

Normally, I’d use UnsafeRawBufferPointer for this, but I need the buffer to
be a vector (i.e. with append(_:)), and for it to return a Swift-managed
Array. How should I do this? The project does not use Foundation.
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Discourse forum rollout next week!

2018-01-10 Thread Charles Srstka via swift-users
:thumbsup:

Charles

> On Jan 10, 2018, at 2:22 PM, Nicole Jacque via swift-users 
>  wrote:
> 
> Hi All-
> 
> First of all, a big thank you to everyone who has provided feedback on our 
> prototype Discourse forum. We are ready to move forward with the transition!  
> The schedule will be:
> 
> 1/17 ~ 6PM Pacific:  We will be putting the mailing lists into suspend mode 
> in order to do the final export of data for import to the forums
> 1/19 (exact time TBD) - forums will be up and in production mode.  We’ll send 
> out one last email at that time to let everyone know.
> 
> During the process, I’ll try to keep some status available at 
> forums.swift.org, but expect about a day and a half of outage time between 
> the mailing lists going down and the forums being ready.
> 
> If you need to contact the Swift infrastructure team during the outage period 
> the infrastruct...@swift.org email will continue to work.
> 
> Thanks!
> nicole
> ___
> 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] Discourse forum rollout next week!

2018-01-10 Thread Nicole Jacque via swift-users
Hi All-

First of all, a big thank you to everyone who has provided feedback on our 
prototype Discourse forum. We are ready to move forward with the transition!  
The schedule will be:

1/17 ~ 6PM Pacific:  We will be putting the mailing lists into suspend mode in 
order to do the final export of data for import to the forums
1/19 (exact time TBD) - forums will be up and in production mode.  We’ll send 
out one last email at that time to let everyone know.

During the process, I’ll try to keep some status available at forums.swift.org, 
but expect about a day and a half of outage time between the mailing lists 
going down and the forums being ready.

If you need to contact the Swift infrastructure team during the outage period 
the infrastruct...@swift.org email will continue to work.

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


[swift-users] Using String

2018-01-10 Thread Michael Ilseman via swift-users
Hello, I just sent an email to swift-dev titled "State of String: ABI, 
Performance, Ergonomics, and You!” at 
https://lists.swift.org/pipermail/swift-dev/Week-of-Mon-20180108/006407.html, 
whose gist can be found at 
https://gist.github.com/milseman/bb39ef7f170641ae52c13600a512782f 
. It’s very 
heavy on implementation details and potential future directions, but there is a 
section that pertains to swift-users concerning the Discourse migration:

## Community
With Swift’s mailing lists [moving to 
Discourse](https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20171211/042127.html),
 this allows the opportunity for better community engagement and 
cross-referencing posts. We plan on starting an area under the “Using Swift” 
category focusing on idiomatic and/or performant solutions to string 
programming needs. These might be anything from simple programming problems to 
make-my-parser-faster challenges.

While this provides a community benefit by showing how best to use String, our 
ulterior motive is to mine posts looking for benchmarks, API gaps, and 
representative code that new features could improve. We’ll also, of course, 
want to bikeshed the name! My vote is for “String Dojo”, but there’s probably a 
reason I don’t normally name things.


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


[swift-users] protocol conformance question

2018-01-10 Thread Swarbrick, Frank via swift-users
Is there a way I can specify that all integer types conform to MyProtocol 
without naming them explicitly like this??

protocol MyProtocol {}
extension String: MyProtocol {}
extension Int: MyProtocol {}
extension UInt8: MyProtocol {}
[...]

I tried the following:
extension FixedWidthInteger: MyProtocol {}
but get "error: extension of protocol 'FixedWidthInteger' cannot have an 
inheritance clause".

Thanks,
Frank


The information contained in this electronic communication and any document 
attached hereto or transmitted herewith is confidential and intended for the 
exclusive use of the individual or entity named above. If the reader of this 
message is not the intended recipient or the employee or agent responsible for 
delivering it to the intended recipient, you are hereby notified that any 
examination, use, dissemination, distribution or copying of this communication 
or any part thereof is strictly prohibited. If you have received this 
communication in error, please immediately notify the sender by reply e-mail 
and destroy this communication. Thank you.
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] defaultCalendarForNewEvents is defined as optional however can't use optional binding to check if it's nil

2018-01-10 Thread Jordan Rose via swift-users
Nothing specific. A lot of minor issues were corrected in the Xcode 9 release 
with a nod towards maintaining source compatibility, and most of them weren't 
release-noted.

Jordan


> On Jan 10, 2018, at 10:21, Filiz Kurban  wrote:
> 
> Thanks for your response. I will check that now! In the meantime, is there a 
> release note that states this? I have a stackover flow question on this and 
> would love to resolve it.
> 
> On Wed, Jan 10, 2018 at 10:13 AM, Jordan Rose via swift-users 
> > wrote:
> Hi, Filiz. Are you sure you're using Swift 4 and not the Swift 3 
> compatibility mode? 'defaultCalendarForNewEvents' was marked non-optional in 
> Swift 3 by accident and that was fixed in Swift 4.
> 
> Jordan
> 
> 
>> On Jan 10, 2018, at 08:59, Filiz Kurban via swift-users 
>> > wrote:
>> 
>> Hello,
>> 
>> I'm adding a new functionality in my app, which is the ability to add an 
>> event in the default calendar set up on the phone. In the implementation, I 
>> get the permission and am ready to add the event. I check to see if there is 
>> an actual default calendar through the use of optional binding, but I get 
>> the error:
>> 
>> Initializer for conditional binding must have Optional type, not 'EKCalendar'
>> 
>> Now, defaultCalendarForNewEvents is an Optional (see declaration below) and 
>> it should be perfectly fine to use optional binding to check if it's nil or 
>> not. What am I missing?
>> 
>> defaultCalendarForNewEvents definition in EKEventStore.h:
>> 
>> open var defaultCalendarForNewEvents: EKCalendar? { get }
>> 
>> I'm using Swift 4 on iOS11.2
>> 
>> if let defaultCalendar = eventStore.defaultCalendarForNewEvents { <-- error 
>> line
>> newEvent.title = "Some Event Name"
>> newEvent.startDate = Date()
>> newEvent.endDate = Date()
>> }
>> 
>> Thank you for your help in advance.
>> 
>> 
>> ___
>> 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 mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] defaultCalendarForNewEvents is defined as optional however can't use optional binding to check if it's nil

2018-01-10 Thread Filiz Kurban via swift-users
Thanks for your response. I will check that now! In the meantime, is there
a release note that states this? I have a stackover flow question on this
and would love to resolve it.

On Wed, Jan 10, 2018 at 10:13 AM, Jordan Rose via swift-users <
swift-users@swift.org> wrote:

> Hi, Filiz. Are you sure you're using Swift 4 and not the Swift 3
> compatibility mode? 'defaultCalendarForNewEvents' was marked non-optional
> in Swift 3 by accident and that was fixed in Swift 4.
>
> Jordan
>
>
> On Jan 10, 2018, at 08:59, Filiz Kurban via swift-users <
> swift-users@swift.org> wrote:
>
> Hello,
>
> I'm adding a new functionality in my app, which is the ability to add an
> event in the default calendar set up on the phone. In the implementation, I
> get the permission and am ready to add the event. I check to see if there
> is an actual default calendar through the use of optional binding, but I
> get the error:
>
> Initializer for conditional binding must have Optional type, not
> 'EKCalendar'
>
> Now, defaultCalendarForNewEvents is an Optional (see declaration below)
> and it should be perfectly fine to use optional binding to check if it's
> nil or not. What am I missing?
>
> defaultCalendarForNewEvents definition in EKEventStore.h:
>
> open var defaultCalendarForNewEvents: EKCalendar? { get }
>
>
> I'm using Swift 4 on iOS11.2
>
> if let defaultCalendar = eventStore.defaultCalendarForNewEvents { <-- error 
> line
> newEvent.title = "Some Event Name"
> newEvent.startDate = Date()
> newEvent.endDate = Date()}
>
>
> Thank you for your help in advance.
>
>
> ___
> 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 mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] defaultCalendarForNewEvents is defined as optional however can't use optional binding to check if it's nil

2018-01-10 Thread Jordan Rose via swift-users
Hi, Filiz. Are you sure you're using Swift 4 and not the Swift 3 compatibility 
mode? 'defaultCalendarForNewEvents' was marked non-optional in Swift 3 by 
accident and that was fixed in Swift 4.

Jordan


> On Jan 10, 2018, at 08:59, Filiz Kurban via swift-users 
>  wrote:
> 
> Hello,
> 
> I'm adding a new functionality in my app, which is the ability to add an 
> event in the default calendar set up on the phone. In the implementation, I 
> get the permission and am ready to add the event. I check to see if there is 
> an actual default calendar through the use of optional binding, but I get the 
> error:
> 
> Initializer for conditional binding must have Optional type, not 'EKCalendar'
> 
> Now, defaultCalendarForNewEvents is an Optional (see declaration below) and 
> it should be perfectly fine to use optional binding to check if it's nil or 
> not. What am I missing?
> 
> defaultCalendarForNewEvents definition in EKEventStore.h:
> 
> open var defaultCalendarForNewEvents: EKCalendar? { get }
> 
> I'm using Swift 4 on iOS11.2
> 
> if let defaultCalendar = eventStore.defaultCalendarForNewEvents { <-- error 
> line
> newEvent.title = "Some Event Name"
> newEvent.startDate = Date()
> newEvent.endDate = Date()
> }
> 
> Thank you for your help in advance.
> 
> 
> ___
> 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] defaultCalendarForNewEvents is defined as optional however can't use optional binding to check if it's nil

2018-01-10 Thread Filiz Kurban via swift-users
Hello,


I'm adding a new functionality in my app, which is the ability to add an
event in the default calendar set up on the phone. In the implementation, I
get the permission and am ready to add the event. I check to see if there
is an actual default calendar through the use of optional binding, but I
get the error:


Initializer for conditional binding must have Optional type, not
'EKCalendar'


Now, defaultCalendarForNewEvents is an Optional (see declaration below) and
it should be perfectly fine to use optional binding to check if it's nil or
not. What am I missing?


defaultCalendarForNewEvents definition in EKEventStore.h:

open var defaultCalendarForNewEvents: EKCalendar? { get }


I'm using Swift 4 on iOS11.2


if let defaultCalendar = eventStore.defaultCalendarForNewEvents { <-- error line
newEvent.title = "Some Event Name"
newEvent.startDate = Date()
newEvent.endDate = Date()}


Thank you for your help in advance.
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users