线程1:致命错误:索引超出for循环范围

时间:2018-02-28 04:12:12

标签: ios swift

在我的<TechnicalProfile Id="AzureADAccountProfile"> <DisplayName>Log in with your work account</DisplayName> <Protocol Name="OpenIdConnect"/> <OutputTokenFormat>JWT</OutputTokenFormat> <Metadata> <Item Key="authorization_endpoint">https://login.microsoftonline.com/common/oauth2/v2.0/authorize</Item> <Item Key="client_id">My ID</Item> <Item Key="DiscoverMetadataByTokenIssuer">true</Item> <Item Key="HttpBinding">POST</Item> <Item Key="IdTokenAudience">My ID</Item> <Item Key="response_types">id_token</Item> <Item Key="scope">openid profile</Item> <Item Key="UsePolicyInRedirectUri">false</Item> <Item Key="ValidTokenIssuerPrefixes">https://login.microsoftonline.com/</Item> </Metadata> <CryptographicKeys> <Key Id="client_secret" StorageReferenceId="B2C_1A_AzureADSecret"/> </CryptographicKeys> <OutputClaims> <OutputClaim ClaimTypeReferenceId="authenticationSource" DefaultValue="enterpriseAuthentication" /> <OutputClaim ClaimTypeReferenceId="displayName" PartnerClaimType="name" /> <OutputClaim ClaimTypeReferenceId="identityProvider" DefaultValue="tid" /> <OutputClaim ClaimTypeReferenceId="socialIdpUserId" PartnerClaimType="oid" /> <OutputClaim ClaimTypeReferenceId="tenantId" PartnerClaimType="tid"/> <OutputClaim ClaimTypeReferenceId="email" PartnerClaimType="unique_name" /> <OutputClaim ClaimTypeReferenceId="givenName" PartnerClaimType="given_name" /> <OutputClaim ClaimTypeReferenceId="surName" PartnerClaimType="family_name" /> <OutputClaim ClaimTypeReferenceId="tenant" /> </OutputClaims> <OutputClaimsTransformations> <OutputClaimsTransformation ReferenceId="CreateRandomUPNUserName"/> <OutputClaimsTransformation ReferenceId="CreateUserPrincipalName"/> <OutputClaimsTransformation ReferenceId="CreateAlternativeSecurityId"/> </OutputClaimsTransformations> <UseTechnicalProfileForSessionManagement ReferenceId="SM-Noop" /> </TechnicalProfile> sampllat数组中包含40个sampllong值,double reflat数组包含9个long

double

1 个答案:

答案 0 :(得分:0)

您的问题出在内循环中,特别是在:

for testing1 in (0...refLat.count).reversed()

那将迭代一个比refLat更多的值,你想要的是:

for testing1 in (0..<refLat.count).reversed()

但一般情况下,您可以直接使用for循环生成的索引来简化代码,因此不要管理自己的counterRcounterS,而是让for循环执行它适合你:

// counterS will be generated and managed by the for loop
for counterS in (0..<sampLat.count) {

    let coordinates = CLLocation(latitude:sampLat[counterS], longitude:sampLong[counterS])

    // same for counterR
    for counterR in (0..<refLat.count).reversed()
    {

        let coordinates2 = CLLocation(latitude:refLat[counterR], longitude:refLong[counterR])

        let distanceInMeters = coordinates.distance(from: coordinates2)

        // I will use string interpolation
        print("distance found - \(distanceInMeters)")

        print("Counter Reference - \(counterR)")

        if distanceInMeters <= 50 {
            print("crossed check point for - \(counterR)")
        } else {
            print("out of range")
        }
        print("---------------------------------------")
    }

    print("Counter Sample \(testing)")
    print("******************************************")

}