2017-02-17 12 views
1

나는이 이상한 버그가 있습니다. 나는 글로벌 BoolCalendarAccess라는이 : 당신이 볼 수 있듯이스위프트 bool 자체가 변경됩니다

var EventStore: EKEventStore! 
var Calendar: NSCalendar! 
var CalendarAccessRequestComplete = false 
var _CalendarAccess = false 
var CalendarAccess: Bool { 
    set(value) 
    { 
     _CalendarAccess = value; 
    } 
    get { 
     return _CalendarAccess; 
    } 
} 

, 나는 그래서 그것을 설정되는 위치 확인하기 위해 중단 점을 넣을 수 그것을 세터와 게터했다. 나는 그랬고 매번 breakpoint를 치는 값은 true이다. 나는 지금까지 CalendarAccess라고 불리는이 변수가 있기 때문에 절대로 _CalendarAccess을 설정하지 않을 것이라고 확신합니다.

그러나보기 컨트롤러에서 다음을 수행하면 CalendarAccessfalse입니다!

@IBAction func saveEvent(_ sender: Any) { 

    if(CalendarAccess) 
    { 
     let event = EKEvent(eventStore: EventStore) 
     event.title = "My Event" 
     event.startDate = Date(); 
     event.endDate = Calendar.date(byAdding: .hour, value: 1, to: Date(), options: .matchFirst)! 
     event.notes = "A note" 
     event.calendar = EventStore.defaultCalendarForNewEvents 
     do 
     { 
      try EventStore.save(event, span: .thisEvent) 
     } catch 
     { 
      print("Unable to save event") 
     } 
    } 
    else 
    { 
     ErrorAlert(title: "No calendar access", text: "Please give the app access to your calendar. You can do that in your iOS device's settings.") 
    } 
} 

변수가 어떤보기 나 컨트롤러와도 관련이없는 전역 변수입니다.

마지막 코드 블록의 출처 컨트롤러가 모달로 표시됩니다 (해당 정보가 전혀 유용하지 않은 경우).

편집 :CalendarAccess는 한 곳에서 설정 (AppDelegate에) :

func updateCalendarAccess() 
{ 
    Calendar = NSCalendar.current as NSCalendar! 
    CalendarAccessRequestComplete = false 

    EventStore = EKEventStore() 
    EventStore.requestAccess(to: .event, completion: { 
     (access: Bool, e: Error?) in 

     CalendarAccessRequestComplete = true 

     CalendarAccess = access; 

     return 

    }) 

    while(!CalendarAccessRequestComplete) { } 
} 

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool { 

    // Override point for customization after application launch. 

    updateCalendarAccess() 

    return true 
} 

편집 :

2017-02-17 13:58:00.980237 Calendar[16695:5163026] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles 
2017-02-17 13:58:00.989165 Calendar[16695:5163026] [MC] Reading from public effective user settings. 
: 나는 @IBAction func saveEvent를 호출 버튼을 누를 때
나는이 메시지를 얻을

편집 : 모달로 제공되는보기 컨트롤러를 닫을 때 (saveEvent func)을 입력하고 CalendarAccess의 값을 기록하면 다시 적용됩니다. 그리고 setter 중단 점이 맞지 않습니다.

편집 : VC를 제시 할 때 _CalendarAccess의 값이 초기 값으로 돌아가는 것처럼 보입니다. var _CalendarAccess = falsevar _CalendarAccess = true으로 변경하면 VC가 표시 될 때 참입니다. 또한 Calendar 변수는 VC가 표시 될 때 nil이지만 그렇지 않은 경우는 표시되지 않습니다.

+1

* * 정확히 * 당신은'_CalendarAccess'가 참이된다고 생각합니까? 문제를 보여주는 (최소) * 자체 포함 * 예를 게시 할 수 있습니까? setter 메서드의 중단 점이 적중합니까? 그렇다면 호출 스택은 무엇입니까? 아마도 그것은 쓰레기를 표시하는 디버거 일뿐일까요? setter와 getter 모두에'print (_CalendarAccess)'를 추가하십시오. –

+0

그래서'_CalendarAccess = true' 줄 아래에'print (_CalendarAccess)'를 추가했습니다. 그것은'saveEvent' 함수가 호출되기 전에'true'를 한 번 출력합니다. 하지만 여전히 오류 경고가 표시됩니다. – edvinHolm

+0

func saveEvent의 코드가 CalenderAccess에 질문합니다. getter는 false로 설정된 _CalendarAccess의 값을 반환합니다. 실제로 _CalendarAccess를 true로 설정하지 않으면 항상 false를 반환합니다. – Magnas

답변

2

프로젝트에는 동일한 이름의 프레임 워크가 포함되어있어 컴파일러가 여러 값으로 동일한 값을 찾습니다. 프레임 워크 제거, 문제 해결 :)