2

I tried to use this code for collectionView How to make a simple collection view with Swift

but for swift 3 I added these changes in viewController

    import UIKit
class ViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {

    let reuseIdentifier = "cell" // also enter this string as the cell identifier in the storyboard
    var items = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48"]


    // MARK: - UICollectionViewDataSource protocol

    // tell the collection view how many cells to make
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return self.items.count
    }

    // make a cell for each cell index path
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

        // get a reference to our storyboard cell
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! MyCollectionViewCell

        // Use the outlet in our custom class to get a reference to the UILabel in the cell
        cell.myLabel.text = self.items[indexPath.item]
        cell.backgroundColor = UIColor.yellow // make cell more visible in our example project

        return cell
    }

    // MARK: - UICollectionViewDelegate protocol

    func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: IndexPath) {
        // handle tap events
        print("You selected cell #\(indexPath.item)!")
    }
}

It works, but in debug area I am getting this

    2016-09-20 00:18:39.299329 retry[6595:491717] subsystem: com.apple.UIKit, category: HIDEventFiltered, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1, privacy_setting: 2, enable_private_data: 0
2016-09-20 00:18:39.319250 retry[6595:491717] subsystem: com.apple.UIKit, category: HIDEventIncoming, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1, privacy_setting: 2, enable_private_data: 0
2016-09-20 00:18:39.375574 retry[6595:491699] subsystem: com.apple.BaseBoard, category: MachPort, enable_level: 1, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 0, privacy_setting: 0, enable_private_data: 0
2016-09-20 00:18:39.436027 retry[6595:491572] subsystem: com.apple.UIKit, category: StatusBar, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1, privacy_setting: 2, enable_private_data: 0
2016-09-20 00:18:39.689342 retry[6595:491572] subsystem: com.apple.BackBoardServices.fence, category: App, enable_level: 1, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 0, privacy_setting: 0, enable_private_data: 0
2016-09-20 00:18:56.028502 retry[6595:491572] subsystem: com.apple.UIKit, category: Touch, enable_level: 0, persist_level: 0, default_ttl: 1, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1, privacy_setting: 2, enable_private_data: 0
2016-09-20 00:18:56.031374 retry[6595:491572] subsystem: com.apple.UIKit, category: Gesture, enable_level: 0, persist_level: 0, default_ttl: 1, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1, privacy_setting: 2, enable_private_data: 0
2016-09-20 00:18:56.034089 retry[6595:491572] subsystem: com.apple.UIKit, category: GestureEnvironment, enable_level: 0, persist_level: 0, default_ttl: 1, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1, privacy_setting: 2, enable_private_data: 0
2016-09-20 00:18:56.035698 retry[6595:491572] subsystem: com.apple.UIKit, category: GestureExclusion, enable_level: 0, persist_level: 0, default_ttl: 1, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1, privacy_setting: 2, enable_private_data: 0
2016-09-20 02:07:46.530726 retry[6595:491572] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /Users/joodi/Library/Developer/CoreSimulator/Devices/1DF7F969-AD53-4D2B-82B5-4999B5FC23E8/data/Containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
2016-09-20 02:07:46.531996 retry[6595:491572] [MC] Reading from private effective user settings.

also when I press any cell nothing happens, I think didSelectItemAtIndexPath not working

Community
  • 1
  • 1
joda
  • 581
  • 1
  • 6
  • 16

1 Answers1

1

A.didSelectItemAtIndexPath

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
    // handle tap events
    print("You selected cell #\(indexPath.item)!")
}

If you need more about declaring functions then see on Apple Swift 3 documentation.

B.Specify environment variables to disable unwanted logs

  1. go to Product -> Scheme -> Edit Scheme on Xcode Menu.

    enter image description here

  2. In the left column, select the Run scheme action.

  3. Click Arguments at the top of the right column.
  4. To add an environment variable, click the Add button (+) at the bottom of the Environment Variables table and enter the variable name as OS_ACTIVITY_MODE and value as DISABLE or disable. Then click close.

    enter image description here

If you confused, then see my video.

If you need More about Xcode, then see on apple Xcode Help page.

Rajamohan S
  • 6,709
  • 5
  • 31
  • 51